Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
line.cpp
1 
2 /***************************************************************************
3  * line.cpp - A line
4  *
5  * Created: Fri Sep 28 16:12:33 2007
6  * Copyright 2007 Daniel Beck
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <geometry/line.h>
25 #include <utils/math/angle.h>
26 #include <math.h>
27 #include <iostream>
28 
29 namespace fawkes {
30 
31 /** @class Line <geometry/line.h>
32  * Well, what can one say about a straight line?
33  */
34 
35 /* @var Line::mBasePoint
36  * A point that lies on the line (Aufpunkt)
37  */
38 
39 /* @var Line::mDirection
40  * A vector pointing in the direction of the line
41  */
42 
43 
44 /**Constructor.
45  * @param p a point on the line ("Aufpunkt")
46  * @param v a vector that lies on the line
47  */
48 Line::Line(const HomPoint& p, const HomVector& v)
49  : GeomObj(HomTransform().reset(), HomPoint(0.0, 0.0, 0.0))
50 {
51  mBasePoint = p;
52  mDirection = v;
53 
54  // align direction vector with x-axis of object's CS
55  // project the direction vector in the xy-plane and calculate
56  // the angle to the x-axis
57  float z_angle = atan( mDirection.y() / mDirection.x() );
58  // project the direction vector in the xy-plane and calculate
59  // the angle between itself and the projected vector
60  HomVector direction_xy = mDirection;
61  direction_xy.z() = 0.0;
62  float y_angle = -atan( mDirection.z() / direction_xy.length() );
63 
64  // first rotate around the z-axis ...
65  mToRefCS.rotate_z(z_angle);
66  // then around the y-axis
67  mToRefCS.rotate_y(y_angle);
68 
69  mToRefCS.trans(mBasePoint.x(), mBasePoint.y(), mBasePoint.z());
70 
71  mChanged = true;
72 }
73 
74 
75 /**Constructor.
76  * @param p1 one point that lies on the line
77  * @param p2 another point that lies on the line
78  */
79 Line::Line(const HomPoint& p1, const HomPoint& p2)
80  : GeomObj(HomTransform().reset(), HomPoint(0.0, 0.0, 0.0))
81 {
82  mBasePoint = p1;
83  mDirection = p2 - p1;
84 
85  // align direction vector with x-axis of object's CS
86  // project the direction vector in the xy-plane and calculate
87  // the angle to the x-axis
88  float z_angle = atan( mDirection.y() / mDirection.x() );
89  // project the direction vector in the xy-plane and calculate
90  // the angle between itself and the projected vector
91  HomVector direction_xy = mDirection;
92  direction_xy.z() = 0.0;
93  float y_angle = -atan( mDirection.z() / direction_xy.length() );
94 
95  // first rotate around the z-axis ...
96  mToRefCS.rotate_z(z_angle);
97  // then around the y-axis
98  mToRefCS.rotate_y(y_angle);
99 
100  mToRefCS.trans(mBasePoint.x(), mBasePoint.y(), mBasePoint.z());
101 
102  mChanged = true;
103 }
104 
105 
106 /**Destructor */
108 {
109 }
110 
111 
112 /**Apply a transformation to the line.
113  * @param t transform
114  * @return a reference to itself
115  */
116 Line&
118 {
119  _apply_transform(t);
120 
121  return *this;
122 }
123 
124 
125 /**Apply a transformation to the line wrt. the reference CS.
126  * @param t transform
127  * @return a reference to itself
128  */
129 Line&
131 {
132  _apply_transform_ref(t);
133 
134  return *this;
135 }
136 
137 
138 /**Translate the object wrt. its local CS.
139  * @param trans_x translation along the x-axis
140  * @param trans_y translation along the y-axis
141  * @param trans_z translation along the z-axis
142  * @return a reference to *this
143  */
144 Line&
145 Line::trans(float trans_x, float trans_y, float trans_z)
146 {
147  _trans(trans_x, trans_y, trans_z);
148 
149  return *this;
150 }
151 
152 
153 /**Translate the object wrt. the reference CS.
154  * @param trans_x translation along the x-axis
155  * @param trans_y translation along the y-axis
156  * @param trans_z translation along the z-axis
157  * @return a reference to *this
158  */
159 Line&
160 Line::trans_ref(float trans_x, float trans_y, float trans_z)
161 {
162  _trans_ref(trans_x, trans_y, trans_z);
163 
164  return *this;
165 }
166 
167 
168 /**Rotate the object around the x-axis of its CS.
169  * @param angle the angle
170  * @return a reference to *this
171  */
172 Line&
173 Line::rotate_x(float angle)
174 {
175  _rotate_x(angle);
176 
177  return *this;
178 }
179 
180 
181 /**Rotate the object around the y-axis of its CS.
182  * @param angle the angle
183  * @return a reference to *this
184  */
185 Line&
186 Line::rotate_y(float angle)
187 {
188  _rotate_y(angle);
189 
190  return *this;
191 }
192 
193 
194 /**Rotate the object around the z-axis of its CS.
195  * @param angle the angle
196  * @return a reference to *this
197  */
198 Line&
199 Line::rotate_z(float angle)
200 {
201  _rotate_z(angle);
202 
203  return *this;
204 }
205 
206 
207 /**Rotate the object around the x-axis of the reference CS.
208  * @param angle the angle
209  * @return a reference to *this
210  */
211 Line&
212 Line::rotate_x_ref(float angle)
213 {
214  _rotate_x_ref(angle);
215 
216  return *this;
217 }
218 
219 
220 /**Rotate the object around the y-axis of the reference CS.
221  * @param angle the angle
222  * @return a reference to *this
223  */
224 Line&
225 Line::rotate_y_ref(float angle)
226 {
227  _rotate_y_ref(angle);
228 
229  return *this;
230 }
231 
232 
233 /**Rotate the object around the z-axis of the reference CS.
234  * @param angle the angle
235  * @return a reference to *this
236  */
237 Line&
238 Line::rotate_z_ref(float angle)
239 {
240  _rotate_z_ref(angle);
241 
242  return *this;
243 }
244 
245 } // end namespace fawkes
Line & rotate_y(float angle)
Rotate the object around the y-axis of its CS.
Definition: line.cpp:186
virtual ~Line()
Destructor.
Definition: line.cpp:107
Line & trans_ref(float trans_x, float trans_y, float trans_z)
Translate the object wrt.
Definition: line.cpp:160
Line & apply_transform_ref(const HomTransform &t)
Apply a transformation to the line wrt.
Definition: line.cpp:130
virtual float y() const
RO-getter for y.
Definition: hom_coord.cpp:115
Line & rotate_y_ref(float angle)
Rotate the object around the y-axis of the reference CS.
Definition: line.cpp:225
Line & rotate_z_ref(float angle)
Rotate the object around the z-axis of the reference CS.
Definition: line.cpp:238
Line & rotate_x(float angle)
Rotate the object around the x-axis of its CS.
Definition: line.cpp:173
Line & rotate_x_ref(float angle)
Rotate the object around the x-axis of the reference CS.
Definition: line.cpp:212
This class describes a homogeneous transformation.
Definition: hom_transform.h:31
A homogeneous point.
Definition: hom_point.h:33
Line & rotate_z(float angle)
Rotate the object around the z-axis of its CS.
Definition: line.cpp:199
Line & apply_transform(const HomTransform &t)
Apply a transformation to the line.
Definition: line.cpp:117
virtual float z() const
RO-getter for z.
Definition: hom_coord.cpp:145
A homogeneous vector.
Definition: hom_vector.h:31
Line(const HomPoint &p, const HomVector &v)
Constructor.
Definition: line.cpp:48
Well, what can one say about a straight line?
Definition: line.h:31
virtual float x() const
RO-getter for x.
Definition: hom_coord.cpp:85
Line & trans(float trans_x, float trans_y, float trans_z)
Translate the object wrt.
Definition: line.cpp:145