line.cpp

00001 
00002 /***************************************************************************
00003  *  line.cpp - A line
00004  *
00005  *  Created: Fri Sep 28 16:12:33 2007
00006  *  Copyright  2007  Daniel Beck
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <geometry/line.h>
00025 #include <utils/math/angle.h>
00026 #include <math.h>
00027 #include <iostream>
00028 
00029 namespace fawkes {
00030 
00031 /** @class Line <geometry/line.h>
00032  * Well, what can one say about a straight line?
00033  */
00034 
00035 /* @var Line::mBasePoint
00036  * A point that lies on the line (Aufpunkt)
00037  */
00038 
00039 /* @var Line::mDirection
00040  * A vector pointing in the direction of the line
00041  */
00042 
00043 
00044 /**Constructor.
00045  * @param p a point on the line ("Aufpunkt")
00046  * @param v a vector that lies on the line
00047  */
00048 Line::Line(const HomPoint& p, const HomVector& v)
00049   : GeomObj(HomTransform().reset(), HomPoint(0.0, 0.0, 0.0))
00050 {
00051   mBasePoint = p;
00052   mDirection = v;
00053 
00054   // align direction vector with x-axis of object's CS
00055   // project the direction vector in the xy-plane and calculate
00056   // the angle to the x-axis
00057   float z_angle = atan( mDirection.y() / mDirection.x() );
00058   // project the direction vector in the xy-plane and calculate
00059   // the angle between itself and the projected vector
00060   HomVector direction_xy = mDirection;
00061   direction_xy.z() = 0.0;
00062   float y_angle = -atan( mDirection.z() / direction_xy.length() );
00063 
00064   // first rotate around the z-axis ...
00065   mToRefCS.rotate_z(z_angle);
00066   // then around the y-axis
00067   mToRefCS.rotate_y(y_angle);
00068 
00069   mToRefCS.trans(mBasePoint.x(), mBasePoint.y(), mBasePoint.z());
00070   
00071   mChanged = true;
00072 }
00073 
00074 
00075 /**Constructor.
00076  * @param p1 one point that lies on the line
00077  * @param p2 another point that lies on the line
00078  */
00079 Line::Line(const HomPoint& p1, const HomPoint& p2)
00080   : GeomObj(HomTransform().reset(), HomPoint(0.0, 0.0, 0.0))
00081 {
00082   mBasePoint = p1;
00083   mDirection = p2 - p1;
00084 
00085   // align direction vector with x-axis of object's CS
00086   // project the direction vector in the xy-plane and calculate
00087   // the angle to the x-axis
00088   float z_angle = atan( mDirection.y() / mDirection.x() );
00089   // project the direction vector in the xy-plane and calculate
00090   // the angle between itself and the projected vector
00091   HomVector direction_xy = mDirection;
00092   direction_xy.z() = 0.0;
00093   float y_angle = -atan( mDirection.z() / direction_xy.length() );
00094 
00095   // first rotate around the z-axis ...
00096   mToRefCS.rotate_z(z_angle);
00097   // then around the y-axis
00098   mToRefCS.rotate_y(y_angle);
00099 
00100   mToRefCS.trans(mBasePoint.x(), mBasePoint.y(), mBasePoint.z());
00101   
00102   mChanged = true;
00103 }
00104 
00105 
00106 /**Destructor */
00107 Line::~Line()
00108 {
00109 }
00110 
00111 
00112 /**Apply a transformation to the line.
00113  * @param t transform
00114  * @return a reference to itself
00115  */
00116 Line&
00117 Line::apply_transform(const HomTransform& t)
00118 {
00119   _apply_transform(t);
00120 
00121   return *this;
00122 }
00123 
00124 
00125 /**Apply a transformation to the line wrt. the reference CS.
00126  * @param t transform
00127  * @return a reference to itself
00128  */
00129 Line&
00130 Line::apply_transform_ref(const HomTransform& t)
00131 {
00132   _apply_transform_ref(t);
00133 
00134   return *this;
00135 }
00136 
00137 
00138 /**Translate the object wrt. its local CS.
00139  * @param trans_x translation along the x-axis
00140  * @param trans_y translation along the y-axis
00141  * @param trans_z translation along the z-axis
00142  * @return a reference to *this
00143  */
00144 Line&
00145 Line::trans(float trans_x, float trans_y, float trans_z)
00146 {
00147   _trans(trans_x, trans_y, trans_z);
00148 
00149   return *this;
00150 }
00151 
00152 
00153 /**Translate the object wrt. the reference CS.
00154  * @param trans_x translation along the x-axis
00155  * @param trans_y translation along the y-axis
00156  * @param trans_z translation along the z-axis
00157  * @return a reference to *this
00158  */
00159 Line&
00160 Line::trans_ref(float trans_x, float trans_y, float trans_z)
00161 {
00162   _trans_ref(trans_x, trans_y, trans_z);
00163 
00164   return *this;
00165 }
00166 
00167 
00168 /**Rotate the object around the x-axis of its CS.
00169  * @param angle the angle
00170  * @return a reference to *this
00171  */
00172 Line&
00173 Line::rotate_x(float angle)
00174 {
00175   _rotate_x(angle);
00176 
00177   return *this;
00178 }
00179 
00180 
00181 /**Rotate the object around the y-axis of its CS.
00182  * @param angle the angle
00183  * @return a reference to *this
00184  */
00185 Line&
00186 Line::rotate_y(float angle)
00187 {
00188   _rotate_y(angle);
00189 
00190   return *this;
00191 }
00192 
00193 
00194 /**Rotate the object around the z-axis of its CS.
00195  * @param angle the angle
00196  * @return a reference to *this
00197  */
00198 Line&
00199 Line::rotate_z(float angle)
00200 {
00201   _rotate_z(angle);
00202 
00203   return *this;
00204 }
00205 
00206 
00207 /**Rotate the object around the x-axis of the reference CS.
00208  * @param angle the angle
00209  * @return a reference to *this
00210  */
00211 Line&
00212 Line::rotate_x_ref(float angle)
00213 {
00214   _rotate_x_ref(angle);
00215 
00216   return *this;
00217 }
00218 
00219 
00220 /**Rotate the object around the y-axis of the reference CS.
00221  * @param angle the angle
00222  * @return a reference to *this
00223  */
00224 Line&
00225 Line::rotate_y_ref(float angle)
00226 {
00227   _rotate_y_ref(angle);
00228 
00229   return *this;
00230 }
00231 
00232 
00233 /**Rotate the object around the z-axis of the reference CS.
00234  * @param angle the angle
00235  * @return a reference to *this
00236  */
00237 Line&
00238 Line::rotate_z_ref(float angle)
00239 {
00240   _rotate_z_ref(angle);
00241 
00242   return *this;
00243 }
00244 
00245 } // end namespace fawkes

Generated on Tue Feb 22 13:31:17 2011 for Fawkes API by  doxygen 1.4.7