line_2d.tpp

Go to the documentation of this file.
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 */
00031 /*----------------------------------------------------------------------------*/
00035 template<class T>
00036 claw::math::line_2d<T>::line_2d()
00037 {
00038 
00039 } // line_2d::line_2d() [constructor]
00040 
00041 /*----------------------------------------------------------------------------*/
00046 template<class T>
00047 template<class U>
00048 claw::math::line_2d<T>::line_2d( const line_2d<U>& that )
00049   : origin(that.origin), direction(that.direction)
00050 {
00051 
00052 } // line_2d::line_2d() [copy constructor]
00053 
00054 /*----------------------------------------------------------------------------*/
00060 template<class T>
00061 claw::math::line_2d<T>::line_2d
00062 ( const point_type& _origin, const direction_type& _direction )
00063   : origin(_origin), direction(_direction)
00064 {
00065 
00066 } // line_2d::line_2d() [constructor with values]
00067 
00068 /*----------------------------------------------------------------------------*/
00076 template<class T>
00077 claw::math::line_2d<T>::line_2d( const value_type& ox, const value_type& oy,
00078                                  const value_type& dx, const value_type& dy )
00079   : origin(ox, oy), direction(dx, dy)
00080 {
00081 
00082 } // line_2d::line_2d() [constructor with detailed origin & direction]
00083 
00084 /*----------------------------------------------------------------------------*/
00089 template<class T>
00090 bool claw::math::line_2d<T>::parallel( const self_type& that ) const
00091 {
00092   return !( (direction.x * that.direction.y)
00093             - (that.direction.x * direction.y) );
00094 } // line_2d::parallel()
00095 
00096 /*----------------------------------------------------------------------------*/
00101 template<class T>
00102 bool claw::math::line_2d<T>::orthogonal( const self_type& that ) const
00103 {
00104   return !( direction.dot_product( that.direction ) );
00105 } // line_2d::orthogonal()
00106 
00107 /*----------------------------------------------------------------------------*/
00113 template<class T>
00114 typename claw::math::line_2d<T>::point_type
00115 claw::math::line_2d<T>::intersection( const self_type& that ) const
00116 {
00117   point_type result;
00118 
00119   if ( ! parallel( that ) )
00120     {
00121       point_type delta( that.origin - origin );
00122       value_type n, m;
00123       
00124       n = direction.x * delta.y - direction.y * delta.x;
00125       m = that.direction.x * direction.y - direction.x * that.direction.y;
00126 
00127       result.x = that.origin.x + (n * that.direction.x) / m;
00128       result.y = that.origin.y + (n * that.direction.y) / m;
00129     }
00130 
00131   return result;
00132 } // line_2d::intersection()
00133 
00134 /*----------------------------------------------------------------------------*/
00139 template<class T>
00140 typename claw::math::line_2d<T>::value_type
00141 claw::math::line_2d<T>::y_value( const value_type& x ) const
00142 {
00143   return (direction.y * (x - origin.x) + direction.x * origin.y) / direction.x;
00144 } // line_2d::y_value()

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1