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