Claw  1.7.3
line_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 */
31 /*----------------------------------------------------------------------------*/
35 template<class T>
37 {
38 
39 } // line_2d::line_2d() [constructor]
40 
41 /*----------------------------------------------------------------------------*/
46 template<class T>
47 template<class U>
49  : origin(that.origin), direction(that.direction)
50 {
51 
52 } // line_2d::line_2d() [copy constructor]
53 
54 /*----------------------------------------------------------------------------*/
60 template<class T>
62 ( const point_type& _origin, const direction_type& _direction )
63  : origin(_origin), direction(_direction)
64 {
65 
66 } // line_2d::line_2d() [constructor with values]
67 
68 /*----------------------------------------------------------------------------*/
76 template<class T>
78  const value_type& dx, const value_type& dy )
79  : origin(ox, oy), direction(dx, dy)
80 {
81 
82 } // line_2d::line_2d() [constructor with detailed origin & direction]
83 
84 /*----------------------------------------------------------------------------*/
89 template<class T>
91 {
92  return !( (direction.x * that.direction.y)
93  - (that.direction.x * direction.y) );
94 } // line_2d::parallel()
95 
96 /*----------------------------------------------------------------------------*/
101 template<class T>
103 {
104  return !( direction.dot_product( that.direction ) );
105 } // line_2d::orthogonal()
106 
107 /*----------------------------------------------------------------------------*/
113 template<class T>
116 {
117  point_type result;
118 
119  if ( ! parallel( that ) )
120  {
121  point_type delta( that.origin - origin );
122  value_type n, m;
123 
124  n = direction.x * delta.y - direction.y * delta.x;
125  m = that.direction.x * direction.y - direction.x * that.direction.y;
126 
127  result.x = that.origin.x + (n * that.direction.x) / m;
128  result.y = that.origin.y + (n * that.direction.y) / m;
129  }
130 
131  return result;
132 } // line_2d::intersection()
133 
134 /*----------------------------------------------------------------------------*/
139 template<class T>
142 {
143  return (direction.y * (x - origin.x) + direction.x * origin.y) / direction.x;
144 } // line_2d::y_value()