00001 /* 00002 CLAW - a C++ Library Absolutely Wonderful 00003 00004 CLAW is a free library without any particular aim but being useful to 00005 anyone. 00006 00007 Copyright (C) 2005-2008 Julien Jorge 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 contact: julien_jorge@yahoo.fr 00024 */ 00030 #include <cmath> 00031 00032 /*----------------------------------------------------------------------------*/ 00036 template<class T> 00037 claw::math::vector_2d<T>::vector_2d() 00038 { 00039 00040 } // vector_2d::vector_2d() [constructor] 00041 00042 /*----------------------------------------------------------------------------*/ 00046 template<class T> 00047 template<class U> 00048 claw::math::vector_2d<T>::vector_2d(const coordinate_2d<U>& that) 00049 : super(that) 00050 { 00051 00052 } // vector_2d::vector_2d() [copy constructor] 00053 00054 /*----------------------------------------------------------------------------*/ 00058 template<class T> 00059 template<class U> 00060 claw::math::vector_2d<T>::vector_2d 00061 ( const coordinate_2d<U>& p1, const coordinate_2d<U>& p2 ) 00062 : super( p2.x - p1.x, p2.y - p1.y ) 00063 { 00064 00065 } // vector_2d::vector_2d() [constructor from two points] 00066 00067 /*----------------------------------------------------------------------------*/ 00073 template<class T> 00074 claw::math::vector_2d<T>::vector_2d(const value_type& _x, const value_type& _y) 00075 : super(_x, _y) 00076 { 00077 00078 } // vector_2d::vector_2d() [constructor whit values] 00079 00080 /*----------------------------------------------------------------------------*/ 00084 template<class T> 00085 typename claw::math::vector_2d<T>::value_type 00086 claw::math::vector_2d<T>::length() const 00087 { 00088 return std::sqrt( (this->x * this->x) + (this->y * this->y) ); 00089 } // vector_2d::length() 00090 00091 /*----------------------------------------------------------------------------*/ 00095 template<class T> 00096 void claw::math::vector_2d<T>::normalize() 00097 { 00098 value_type l = length(); 00099 00100 if (l != 0) 00101 { 00102 this->x /= l; 00103 this->y /= l; 00104 } 00105 } // vector_2d::normalize() 00106 00107 /*----------------------------------------------------------------------------*/ 00111 template<class T> 00112 claw::math::vector_2d<T> 00113 claw::math::vector_2d<T>::get_orthonormal_clockwise() const 00114 { 00115 return self_type(this->y, -this->x); 00116 } // vector_2d::get_orthonormal_clockwise() 00117 00118 /*----------------------------------------------------------------------------*/ 00122 template<class T> 00123 claw::math::vector_2d<T> 00124 claw::math::vector_2d<T>::get_orthonormal_anticlockwise() const 00125 { 00126 return self_type(-this->y, this->x); 00127 } // vector_2d::get_orthonormal_anticlockwise() 00128 00129 /*----------------------------------------------------------------------------*/ 00134 template<class T> 00135 typename claw::math::vector_2d<T>::value_type 00136 claw::math::vector_2d<T>::dot_product(const self_type& that) const 00137 { 00138 return this->x * that.x + this->y * that.y; 00139 } // vector_2d::dot_product()