library of assembled shared sources

http://lass.cocamware.com

line_3d.inl

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 
00044 
00045 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_LINE_3D_INL
00046 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_LINE_3D_INL
00047 
00048 
00049 
00050 
00051 #include "line_3d.h"
00052 
00053 
00054 
00055 namespace lass
00056 {
00057 
00058 namespace prim
00059 {
00060 
00061 template <typename T, class NP>
00062 Line3D<T, NP>::Line3D():
00063     support_(),
00064     direction_()
00065 {
00066     LASS_ASSERT(support_.isZero());
00067     LASS_ASSERT(direction_.isZero());
00068 }
00069 
00070 
00071 
00072 template <typename T, class NP>
00073 Line3D<T, NP>::Line3D(const TPoint& iSupport, const TVector& iDirection):
00074     support_(iSupport),
00075     direction_(iDirection)
00076 {
00077     NP::normalize(direction_);
00078 }
00079 
00080 
00081 
00082 template <typename T, class NP>
00083 Line3D<T, NP>::Line3D(const TPoint& iSupport, const TPoint& iLookAt):
00084     support_(iSupport),
00085     direction_(iLookAt - iSupport)
00086 {
00087     NP::normalize(direction_);
00088 }
00089 
00090 
00091 
00092 template <typename T, class NP> inline
00093 const typename Line3D<T, NP>::TPoint&
00094 Line3D<T, NP>::support() const
00095 {
00096     return support_;
00097 }
00098 
00099 
00100 
00101 template <typename T, class NP> inline
00102 typename Line3D<T, NP>::TPoint&
00103 Line3D<T, NP>::support()
00104 {
00105     return support_;
00106 }
00107 
00108 
00109 
00110 /** Return direction of line.
00111  */
00112 template <typename T, class NP> inline
00113 const typename Line3D<T, NP>::TVector&
00114 Line3D<T, NP>::direction() const
00115 {
00116     return direction_;
00117 }
00118 
00119 
00120 
00121 /** Set direction and normalize it if that's the policy
00122  */
00123 template <typename T, class NP> inline
00124 void Line3D<T, NP>::setDirection(const TVector& iDirection)
00125 {
00126     direction_ = iDirection;
00127     NP::normalize(direction_);
00128 }
00129 
00130 
00131 
00132 /** Set direction from support to look-at point.
00133  */
00134 template <typename T, class NP>
00135 void Line3D<T, NP>::lookAt(const TPoint& iLookAt)
00136 {
00137     direction_ = iLookAt - support_;
00138     NP::normalize(direction_);
00139 }
00140 
00141 
00142 
00143 /** return the vector that, if added to the @e projection of @a iPoint, you get @a iPoint again.
00144  *  <tt>iPoint == (almost) project(iPoint) + reject(iPoint)</tt>
00145  */
00146 template<typename T, class NP>
00147 const typename Line3D<T, NP>::TVector
00148 Line3D<T, NP>::reject(const TPoint& iPoint) const
00149 {
00150     return reject(iPoint - support_);
00151 }
00152 
00153 
00154 
00155 /** return the part of @a iVector that is orthogonal to the line.
00156  *  it's the vector that, if added to the @e projection of @a iVector, you get @a iVector again.
00157  *  <tt>iVector == (almost) project(iVector) + reject(iVector)</tt>.
00158  */
00159 template<typename T, class NP>
00160 const typename Line3D<T, NP>::TVector
00161 Line3D<T, NP>::reject(const TVector& iVector) const
00162 {
00163 
00164     return iVector - project(iVector);
00165 }
00166 
00167 
00168 
00169 /** project a point orthogonally onto the line
00170  */
00171 template<typename T, class NP>
00172 const typename Line3D<T, NP>::TPoint
00173 Line3D<T, NP>::project(const TPoint& iPoint) const
00174 {
00175     return support_ + project(iPoint - support_);
00176 }
00177 
00178 
00179 
00180 /** project a vector orthogonally onto the line
00181  */
00182 template<typename T, class NP>
00183 const typename Line3D<T, NP>::TVector
00184 Line3D<T, NP>::project(const TVector& iVector) const
00185 {
00186     return direction_ * NP::divideBySquaredNorm(dot(iVector, direction_), direction_);
00187 }
00188 
00189 
00190 
00191 /** reflect a point orthogonally into the line.
00192  */
00193 template<typename T, class NP>
00194 const typename Line3D<T, NP>::TPoint
00195 Line3D<T, NP>::reflect(const TPoint& iPoint) const
00196 {
00197     return support_ + reflect(iPoint - support_);
00198 }
00199 
00200 
00201 
00202 /** reflect a vector orthogonally to the line
00203  */
00204 template<typename T, class NP>
00205 const typename Line3D<T, NP>::TVector
00206 Line3D<T, NP>::reflect(const TVector& iVector) const
00207 {
00208     return T(2) * project(iVector) - iVector;
00209 }
00210 
00211 
00212 
00213 /** Return point on line by it's parameter.
00214  *  @return support + t * direction
00215  */
00216 template <typename T, class NP>
00217 const typename Line3D<T, NP>::TPoint
00218 Line3D<T, NP>::point(TParam iT) const
00219 {
00220     return support_ + iT * direction_;
00221 }
00222 
00223 
00224 
00225 /** Return parameter of point on the line that is the projection of the given point.
00226  */
00227 template <typename T, class NP>
00228 const typename Line3D<T, NP>::TValue
00229 Line3D<T, NP>::t(const TPoint& iPoint) const
00230 {
00231     return NP::divideBySquaredNorm(dot(iPoint - support_, direction_), direction_);
00232 }
00233 
00234 
00235 
00236 /** Return true if line is valid (direction isn't a zero vector).
00237  */
00238 template <typename T, class NP>
00239 const bool Line3D<T, NP>::isValid() const
00240 {
00241     return !direction_.isZero();
00242 }
00243 
00244 
00245 
00246 /** @relates lass::prim::Line3D
00247  */
00248 template<typename T, class NP>
00249 std::ostream& operator<<(std::ostream& ioOStream, const Line3D<T, NP>& iLine)
00250 {
00251     LASS_ENFORCE(ioOStream) << "{S=" << iLine.support() << ", U=" << iLine.direction() << "}";
00252     return ioOStream;
00253 }
00254 
00255 
00256 
00257 /** @relates lass::prim::Line3D
00258  */
00259 template<typename T, class NP>
00260 io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Line3D<T, NP>& iLine)
00261 {
00262     LASS_ENFORCE_STREAM(ioOStream)
00263         << "<Line3D>\n"
00264         << "<support>" << iLine.support() << "</support>\n"
00265         << "<direction>" << iLine.direction() << "</direction>\n"
00266         << "</Line3D>\n";
00267 
00268     return ioOStream;
00269 }
00270 
00271 
00272 
00273 }
00274 
00275 }
00276 
00277 #endif
00278 
00279 // EOF

Generated on Mon Nov 10 14:20:24 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo