Claw  1.7.3
vector_2d.tpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
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.
13 
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.
18 
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
22 
23  contact: julien.jorge@gamned.org
24 */
30 #include <cmath>
31 
32 /*----------------------------------------------------------------------------*/
36 template<class T>
38 {
39 
40 } // vector_2d::vector_2d() [constructor]
41 
42 /*----------------------------------------------------------------------------*/
46 template<class T>
47 template<class U>
49  : super(that)
50 {
51 
52 } // vector_2d::vector_2d() [copy constructor]
53 
54 /*----------------------------------------------------------------------------*/
58 template<class T>
59 template<class U>
61 ( const coordinate_2d<U>& p1, const coordinate_2d<U>& p2 )
62  : super( p2.x - p1.x, p2.y - p1.y )
63 {
64 
65 } // vector_2d::vector_2d() [constructor from two points]
66 
67 /*----------------------------------------------------------------------------*/
73 template<class T>
75  : super(_x, _y)
76 {
77 
78 } // vector_2d::vector_2d() [constructor whit values]
79 
80 /*----------------------------------------------------------------------------*/
84 template<class T>
87 {
88  return std::sqrt( (this->x * this->x) + (this->y * this->y) );
89 } // vector_2d::length()
90 
91 /*----------------------------------------------------------------------------*/
95 template<class T>
97 {
98  value_type l = length();
99 
100  if (l != 0)
101  {
102  this->x /= l;
103  this->y /= l;
104  }
105 } // vector_2d::normalize()
106 
107 /*----------------------------------------------------------------------------*/
111 template<class T>
114 {
115  return self_type(this->y, -this->x);
116 } // vector_2d::get_orthonormal_clockwise()
117 
118 /*----------------------------------------------------------------------------*/
122 template<class T>
125 {
126  return self_type(-this->y, this->x);
127 } // vector_2d::get_orthonormal_anticlockwise()
128 
129 /*----------------------------------------------------------------------------*/
134 template<class T>
137 {
138  return this->x * that.x + this->y * that.y;
139 } // vector_2d::dot_product()