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_IMPL_LINE_2D_CARTESIAN_INL
00046 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_IMPL_LINE_2D_CARTESIAN_INL
00047
00048 #include "../prim_common.h"
00049 #include "line_2d_cartesian.h"
00050
00051 namespace lass
00052 {
00053 namespace prim
00054 {
00055 namespace impl
00056 {
00057
00058
00059
00060
00061
00062 template<typename T, class NP>
00063 Line2DCartesian<T, NP>::Line2DCartesian():
00064 normal_(),
00065 d_(TNumTraits::zero)
00066 {
00067 LASS_ASSERT(!isValid());
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 template<typename T, class NP>
00080 Line2DCartesian<T, NP>::Line2DCartesian(const TPoint& iSupport, const TPoint& iPoint):
00081 normal_((iPoint - iSupport).perp())
00082 {
00083 NP::normalize(normal_);
00084 d_ = -dot(normal_, iSupport.position());
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 template<typename T, class NP>
00096 Line2DCartesian<T, NP>::Line2DCartesian(const TPoint& iSupport, const TVector& iDirection):
00097 normal_(iDirection.perp())
00098 {
00099 NP::normalize(normal_);
00100 d_ = -dot(normal_, iSupport.position());
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 template<typename T, class NP>
00112 Line2DCartesian<T, NP>::Line2DCartesian(const TVector& iNormal, const TPoint& iSupport):
00113 normal_(iNormal)
00114 {
00115 NP::normalize(normal_);
00116 d_ = -dot(normal_, iSupport.position());
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 template<typename T, class NP>
00128 Line2DCartesian<T, NP>::Line2DCartesian(const TVector& iNormal, TParam iD):
00129 normal_(iNormal),
00130 d_(iD)
00131 {
00132 NP::normalizeAndScale(normal_, d_);
00133 }
00134
00135
00136
00137
00138
00139
00140 template<typename T, class NP>
00141 const typename Line2DCartesian<T, NP>::TPoint Line2DCartesian<T, NP>::support() const
00142 {
00143 return TPoint(normal_ * NP::divideBySquaredNorm(-d_, normal_));
00144 }
00145
00146
00147
00148
00149
00150 template<typename T, class NP>
00151 const typename Line2DCartesian<T, NP>::TVector Line2DCartesian<T, NP>::direction() const
00152 {
00153 return -normal_.perp();
00154 }
00155
00156
00157
00158 template<typename T, class NP>
00159 void Line2DCartesian<T, NP>::getCartesian(TVector& oNormal, TReference oD) const
00160 {
00161 oNormal = normal_;
00162 oD = d_;
00163 }
00164
00165
00166
00167 template<typename T, class NP>
00168 const typename Line2DCartesian<T, NP>::TVector& Line2DCartesian<T, NP>::normal() const
00169 {
00170 return normal_;
00171 }
00172
00173
00174
00175 template<typename T, class NP>
00176 typename Line2DCartesian<T, NP>::TParam Line2DCartesian<T, NP>::d() const
00177 {
00178 return d_;
00179 }
00180
00181
00182
00183
00184
00185 template<typename T, class NP>
00186 const typename Line2DCartesian<T, NP>::TValue
00187 Line2DCartesian<T, NP>::equation(const TPoint& iPoint) const
00188 {
00189 return dot(iPoint.position(), normal_) + d_;
00190 }
00191
00192
00193
00194
00195
00196 template<typename T, class NP>
00197 const typename Line2DCartesian<T, NP>::TValue
00198 Line2DCartesian<T, NP>::equation(const TPoint& iPoint, TParam iRelativeTolerance) const
00199 {
00200 const TValue d = dot(iPoint.position(), normal_);
00201 return num::almostEqual(d, -d_, iRelativeTolerance) ? TNumTraits::zero : (d + d_);
00202 }
00203
00204
00205
00206
00207
00208
00209 template<typename T, class NP>
00210 const typename Line2DCartesian<T, NP>::TVector
00211 Line2DCartesian<T, NP>::reject(const TPoint& iPoint) const
00212 {
00213 return normal_ * NP::divideBySquaredNorm(equation(iPoint), normal_);
00214 }
00215
00216
00217
00218
00219
00220
00221
00222 template<typename T, class NP>
00223 const typename Line2DCartesian<T, NP>::TVector
00224 Line2DCartesian<T, NP>::reject(const TVector& iVector) const
00225 {
00226 return normal_ * NP::divideBySquaredNorm(dot(normal_, iVector), normal_);
00227 }
00228
00229
00230
00231
00232
00233 template<typename T, class NP>
00234 const typename Line2DCartesian<T, NP>::TPoint
00235 Line2DCartesian<T, NP>::project(const TPoint& iPoint) const
00236 {
00237 return iPoint - reject(iPoint);
00238 }
00239
00240
00241
00242
00243
00244 template<typename T, class NP>
00245 const typename Line2DCartesian<T, NP>::TVector
00246 Line2DCartesian<T, NP>::project(const TVector& iVector) const
00247 {
00248 return iVector - reject(iVector);
00249 }
00250
00251
00252
00253
00254
00255 template<typename T, class NP>
00256 const typename Line2DCartesian<T, NP>::TPoint
00257 Line2DCartesian<T, NP>::reflect(const TPoint& iPoint) const
00258 {
00259 return iPoint - T(2) * reject(iPoint);
00260 }
00261
00262
00263
00264
00265
00266 template<typename T, class NP>
00267 const typename Line2DCartesian<T, NP>::TVector
00268 Line2DCartesian<T, NP>::reflect(const TVector& iVector) const
00269 {
00270 return iVector - T(2) * reject(iVector);
00271 }
00272
00273
00274
00275
00276
00277 template<typename T, class NP>
00278 const typename Line2DCartesian<T, NP>::TPoint
00279 Line2DCartesian<T, NP>::point(TParam iT) const
00280 {
00281 return support() + iT * direction();
00282 }
00283
00284
00285
00286
00287
00288 template<typename T, class NP>
00289 const typename Line2DCartesian<T, NP>::TValue Line2DCartesian<T, NP>::t(const TPoint& iPoint) const
00290 {
00291 const TVector dir = direction();
00292 return NP::divideBySquaredNorm(dot(dir, iPoint - support()), dir);
00293 }
00294
00295
00296
00297 template <typename T, class NP>
00298 void Line2DCartesian<T, NP>::flip()
00299 {
00300 normal_ = -normal_;
00301 d_ = -d_;
00302 }
00303
00304
00305
00306
00307
00308 template<typename T, class NP>
00309 const bool Line2DCartesian<T, NP>::isValid() const
00310 {
00311 return !normal_.isZero();
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 template<typename T, class NP>
00328 std::ostream& operator<<(std::ostream& ioOStream, const Line2DCartesian<T, NP>& iLine)
00329 {
00330 LASS_ENFORCE(ioOStream) << "{N=" << iLine.normal() << ", d=" << iLine.d() << "}";
00331 return ioOStream;
00332 }
00333
00334
00335
00336 }
00337
00338 }
00339
00340 }
00341
00342 #endif
00343
00344