2 CLAW - a C++ Library Absolutely Wonderful
4 CLAW is a free library without any particular aim but being useful to
7 Copyright (C) 2005-2011 Julien Jorge
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 contact: julien.jorge@gamned.org
27 * \brief Implementation of claw::math::vector_2d class.
28 * \author Julien Jorge
32 /*----------------------------------------------------------------------------*/
37 claw::math::vector_2d<T>::vector_2d()
40 } // vector_2d::vector_2d() [constructor]
42 /*----------------------------------------------------------------------------*/
44 * \brief Copy constructor.
48 claw::math::vector_2d<T>::vector_2d(const coordinate_2d<U>& that)
52 } // vector_2d::vector_2d() [copy constructor]
54 /*----------------------------------------------------------------------------*/
56 * \brief Construct a vector from two points.
60 claw::math::vector_2d<T>::vector_2d
61 ( const coordinate_2d<U>& p1, const coordinate_2d<U>& p2 )
62 : super( p2.x - p1.x, p2.y - p1.y )
65 } // vector_2d::vector_2d() [constructor from two points]
67 /*----------------------------------------------------------------------------*/
69 * \brief Constructor with initialization.
74 claw::math::vector_2d<T>::vector_2d(const value_type& _x, const value_type& _y)
78 } // vector_2d::vector_2d() [constructor whit values]
80 /*----------------------------------------------------------------------------*/
82 * \brief Gets vector length.
85 typename claw::math::vector_2d<T>::value_type
86 claw::math::vector_2d<T>::length() const
88 return std::sqrt( (this->x * this->x) + (this->y * this->y) );
89 } // vector_2d::length()
91 /*----------------------------------------------------------------------------*/
93 * \brief Normalize the vector.
96 void claw::math::vector_2d<T>::normalize()
98 value_type l = length();
105 } // vector_2d::normalize()
107 /*----------------------------------------------------------------------------*/
109 * \brief Get a vector orthonormal to this vector.
112 claw::math::vector_2d<T>
113 claw::math::vector_2d<T>::get_orthonormal_clockwise() const
115 return self_type(this->y, -this->x);
116 } // vector_2d::get_orthonormal_clockwise()
118 /*----------------------------------------------------------------------------*/
120 * \brief Get a vector orthonormal to this vector.
123 claw::math::vector_2d<T>
124 claw::math::vector_2d<T>::get_orthonormal_anticlockwise() const
126 return self_type(-this->y, this->x);
127 } // vector_2d::get_orthonormal_anticlockwise()
129 /*----------------------------------------------------------------------------*/
131 * \brief Dot product.
132 * \param that The other operand.
135 typename claw::math::vector_2d<T>::value_type
136 claw::math::vector_2d<T>::dot_product(const self_type& that) const
138 return this->x * that.x + this->y * that.y;
139 } // vector_2d::dot_product()