00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
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
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
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
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
00144
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
00156
00157
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
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
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
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
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
00214
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
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
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
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
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