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