Library of Assembled Shared Sources
plane_3d_cartesian.inl
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_IMPL_PLANE_3D_CARTESIAN_INL
46#define LASS_GUARDIAN_OF_INCLUSION_PRIM_IMPL_PLANE_3D_CARTESIAN_INL
47
48#include "../prim_common.h"
49#include "plane_3d_cartesian.h"
50
51namespace lass
52{
53namespace prim
54{
55namespace impl
56{
57
58// --- public --------------------------------------------------------------------------------------
59
60/** initializes to an invalid state.
61 */
62template<typename T, class NP>
64 normal_(),
65 d_(TNumTraits::zero)
66{
67 LASS_ASSERT(!isValid());
68}
69
70
71
72/** Construct a plane through three points.
73 * - normal vector N is given by the cross product N = U x V.
74 * - value d is choosen so that the support point is indeed a point of the plane.
75 */
76template<typename T, class NP>
78 const TPoint& iPointU,
79 const TPoint& iPointV)
80{
81 Plane3DImplDetail::generateCartesian(iSupport, iPointU - iSupport, iPointV - iSupport,
82 normal_, d_);
83 NP::normalizeAndScale(normal_, d_);
84}
85
86
87
88/** construct a plane through a support point and by two direction vectors..
89 * - normal vector N is given by the cross product N = U x V.
90 * - value d is choosen so that the support point is indeed a point of the plane.
91 */
92template<typename T, class NP>
94 const TVector& iDirectionU,
95 const TVector& iDirectionV)
96{
97 Plane3DImplDetail::generateCartesian(iSupport, iDirectionU, iDirectionV, normal_, d_);
98 NP::normalizeAndScale(normal_, d_);
99}
100
103/** Construct a plane through a support point and by a normal vector.
104 * - normal vector N is given by the vector iNormal.
105 * - value d is choosen so that the support point is indeed a point of the plane.
106 */
107template<typename T, class NP>
108Plane3DCartesian<T, NP>::Plane3DCartesian(const TVector& iNormal, const TPoint& iSupport):
109 normal_(iNormal),
110 d_(-dot(iNormal, iSupport.position()))
111{
112 NP::normalizeAndScale(normal_, d_);
115
116
117/** Construct a plane by a cartesian equation N.P + d == 0.
118 * - normal vector N is given by the vector iNormal.
119 * - value d is given by the value iD.
120 */
121template<typename T, class NP>
122Plane3DCartesian<T, NP>::Plane3DCartesian(const TVector& iNormal, TParam iD):
123 normal_(iNormal),
124 d_(iD)
126 NP::normalizeAndScale(normal_, d_);
129
131/** return support point.
132 */
133template<typename T, class NP>
134const typename Plane3DCartesian<T, NP>::TPoint Plane3DCartesian<T, NP>::support() const
136 return TPoint(-d_ * normal_);
137}
138
139
140
141/** return U and V direction vectors
142 */
143template<typename T, class NP>
144void Plane3DCartesian<T, NP>::getDirections(TVector& oDirectionU, TVector& oDirectionV) const
145{
146 Plane3DImplDetail::generateDirections(normal_, oDirectionU, oDirectionV);
147 NP::normalize(oDirectionU);
148 NP::normalize(oDirectionV);
149}
150
151
152
153/** return U direction vector.
154 */
155template<typename T, class NP>
156const typename Plane3DCartesian<T, NP>::TVector Plane3DCartesian<T, NP>::directionU() const
157{
158 TVector directionU;
159 TVector directionV;
161 return directionU;
162}
163
164
165
166/** return V direction vector.
167 */
168template<typename T, class NP>
169const typename Plane3DCartesian<T, NP>::TVector Plane3DCartesian<T, NP>::directionV() const
170{
171 TVector directionU;
172 TVector directionV;
174 return directionV;
175}
176
177
178
179/** return reciprocal vectors for U and V direction vectors
180 */
181template<typename T, class NP>
183 TVector& oReciprocalV) const
184{
185 TVector directionU;
186 TVector directionV;
188 Plane3DImplDetail::generateReciprocal(directionU, directionV, oReciprocalU, oReciprocalV);
189}
190
191
192
193/** return reciprocal for U direction vector.
194 */
195template<typename T, class NP>
196const typename Plane3DCartesian<T, NP>::TVector Plane3DCartesian<T, NP>::reciprocalU() const
197{
198 TVector reciprocalU;
199 TVector reciprocalV;
201 return reciprocalU;
202}
203
204
205
206/** return reciprocal for V direction vector.
207 */
208template<typename T, class NP>
209const typename Plane3DCartesian<T, NP>::TVector Plane3DCartesian<T, NP>::reciprocalV() const
210{
211 TVector reciprocalU;
212 TVector reciprocalV;
214 return reciprocalV;
215}
216
217
218
219template<typename T, class NP>
220void Plane3DCartesian<T, NP>::getCartesian(TVector& oNormal, TReference oD) const
221{
222 oNormal = normal_;
223 oD = d_;
224}
225
226
227
228template<typename T, class NP>
229const typename Plane3DCartesian<T, NP>::TVector& Plane3DCartesian<T, NP>::normal() const
230{
231 return normal_;
232}
233
234
235
236template<typename T, class NP>
237const typename Plane3DCartesian<T, NP>::TParam Plane3DCartesian<T, NP>::d() const
238{
239 return d_;
240}
241
242
243
244/** Return value of point in equation.
245 */
246template<typename T, class NP>
247const typename Plane3DCartesian<T, NP>::TValue
248Plane3DCartesian<T, NP>::equation(const TPoint& iPoint) const
249{
250 return dot(iPoint.position(), normal_) + d_;
251}
252
253
254
255/** Return value of point in equation.
256 */
257template<typename T, class NP>
258const typename Plane3DCartesian<T, NP>::TValue
259Plane3DCartesian<T, NP>::equation(const TPoint& iPoint, TParam iRelativeTolerance) const
260{
261 const TValue a = dot(iPoint.position(), normal_);
262 return num::almostEqual(a, -d_, iRelativeTolerance) ? TNumTraits::zero : (a + d_);
263}
264
265
266
267/** return the vector that, if added to the PROJECTION of iPoint, you get iPoint again.
268 * iPoint == (almost) project(iPoint) + reject(iPoint)
269 */
270template<typename T, class NP>
271const typename Plane3DCartesian<T, NP>::TVector
272Plane3DCartesian<T, NP>::reject(const TPoint& iPoint) const
273{
274 return normal_ * NP::divideBySquaredNorm(equation(iPoint), normal_);
275}
276
277
278
279/** return the part of iVector that is orthogonal to the plane.
280 * it's the vector that, if added to the PROJECTION of iVector, you get iVector again.
281 * iVector == (almost) project(iVector) + reject(iVector).
282 */
283template<typename T, class NP>
284const typename Plane3DCartesian<T, NP>::TVector
285Plane3DCartesian<T, NP>::reject(const TVector& iVector) const
286{
287 return normal_ * NP::divideBySquaredNorm(dot(normal_, iVector), normal_);
288}
289
290
291
292/** project a point orthogonally onto the plane
293 */
294template<typename T, class NP>
295const typename Plane3DCartesian<T, NP>::TPoint
296Plane3DCartesian<T, NP>::project(const TPoint& iPoint) const
297{
298 return iPoint - reject(iPoint);
299}
300
301
302
303/** project a vector orthogonally onto the plane
304 */
305template<typename T, class NP>
306const typename Plane3DCartesian<T, NP>::TVector
307Plane3DCartesian<T, NP>::project(const TVector& iVector) const
308{
309 return iVector - reject(iVector);
310}
311
312
313
314/** reflect a point orthogonally into the plane.
315 */
316template<typename T, class NP>
317const typename Plane3DCartesian<T, NP>::TPoint
318Plane3DCartesian<T, NP>::reflect(const TPoint& iPoint) const
319{
320 return iPoint - 2 * reject(iPoint);
321}
322
323
324
325/** reflect a vector orthogonally into the plane
326 */
327template<typename T, class NP>
328const typename Plane3DCartesian<T, NP>::TVector
329Plane3DCartesian<T, NP>::reflect(const TVector& iVector) const
330{
331 return iVector - 2 * reject(iVector);
332}
333
334
335
336/** return point by filling in the parametric equation: P(u, v) = S + u * U + v * V
337 */
338template<typename T, class NP>
339const typename Plane3DCartesian<T, NP>::TPoint
340Plane3DCartesian<T, NP>::point(TParam iU, TParam iV) const
341{
342 return point(TIndex(iU, iV));
343}
344
345
346
347/** return point by filling in the parametric equation: P(u, v) = S + u * U + v * V
348 */
349template<typename T, class NP>
350const typename Plane3DCartesian<T, NP>::TPoint
352{
353 TVector directionU;
354 TVector directionV;
356 return support() + iUV.x * directionU + iUV.y * directionV;
357}
358
359
360
361/** return UV pair of parameters
362 */
363template<typename T, class NP>
364const typename Plane3DCartesian<T, NP>::TUV
365Plane3DCartesian<T, NP>::uv(const TPoint& iPoint) const
366{
367 TVector reciprocalU;
368 TVector reciprocalV;
370 const TVector relative = iPoint - support();
371 return TUV(dot(relative, reciprocalU), dot(relative, reciprocalV));
372}
373
374
375
376template <typename T, class NP>
377void Plane3DCartesian<T, NP>::flip()
378{
379 normal_ = -normal_;
380 d_ = -d_;
381}
382
383
384
385/** return true if plane is a valid plane (no normal or direction vectors that are zero).
386 */
387template<typename T, class NP>
389{
390 return !normal_.isZero();
391}
392
393
394
395
396// --- protected -----------------------------------------------------------------------------------
397
398
399
400// --- private -------------------------------------------------------------------------------------
401
402
403
404// --- free ----------------------------------------------------------------------------------------
405
406template<typename T, class NP>
407std::ostream& operator<<(std::ostream& ioOStream, const Plane3DCartesian<T, NP>& iPlane)
408{
409 LASS_ENFORCE(ioOStream) << "{N=" << iPlane.normal() << ", d=" << iPlane.d() << "}";
410 return ioOStream;
411}
412
413
414
415}
416
417}
418
419}
420
421#endif
422
423// EOF
implementation of plane 3d with a cartesian equation
const TPoint point(TParam iU, TParam iV) const
return point by filling in the parametric equation: P(u, v) = S + u * U + v * V
const TValue equation(const TPoint &iPoint) const
Return value of point in equation.
void getDirections(TVector &oDirectionU, TVector &oDirectionV) const
return U and V direction vectors
const TVector directionV() const
return V direction vector.
bool isValid() const
return true if plane is a valid plane (no normal or direction vectors that are zero).
const TVector reciprocalV() const
return reciprocal for V direction vector.
const TVector directionU() const
return U direction vector.
const TVector reject(const TPoint &iPoint) const
return the vector that, if added to the PROJECTION of iPoint, you get iPoint again.
const TPoint reflect(const TPoint &iPoint) const
reflect a point orthogonally into the plane.
Plane3DCartesian()
initializes to an invalid state.
const TPoint support() const
return support point.
const TUV uv(const TPoint &iPoint) const
return UV pair of parameters
const TPoint project(const TPoint &iPoint) const
project a point orthogonally onto the plane
const TVector reciprocalU() const
return reciprocal for U direction vector.
void getReciprocals(TVector &oReciprocalU, TVector &oReciprocalV) const
return reciprocal vectors for U and V direction vectors
implementation details of lass::prim
set of geometrical primitives
Definition aabb_2d.h:81
Library for Assembled Shared Sources.
Definition config.h:53
static void generateReciprocal(const Vector3D< T > &iDirU, const Vector3D< T > &iDirV, Vector3D< T > &oReciprocalDirU, Vector3D< T > &oReciprocalDirV)
generate reciprocal direction vectors Ur and Vr given directions U and V.
static void generateDirections(const Vector3D< T > &iNormal, Vector3D< T > &oDirU, Vector3D< T > &oDirV)
Generate directions vectors U and V of parametric equation P = S + x*U + y*V, based on the normal vec...
static void generateCartesian(const Point3D< T > &iSupport, const Vector3D< T > &iDirU, const Vector3D< T > &iDirV, Vector3D< T > &oNormal, T &oD)
Generate cartesian equation out of parametric equation.