00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031
00035 template<class T>
00036 claw::math::line_2d<T>::line_2d()
00037 {
00038
00039 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }