Library of Assembled Shared Sources
line_segment_3d_plane_3d.h
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#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_LINE_SEGMENT_3D_PLANE_3D_H
44#define LASS_GUARDIAN_OF_INCLUSION_PRIM_LINE_SEGMENT_3D_PLANE_3D_H
45
46#include "prim_common.h"
47#include "line_segment_3d.h"
48#include "plane_3d.h"
49
50namespace lass
51{
52namespace prim
53{
54
55/** Find the intersection of a plane and line segment by their parameter t on the ray.
56 * @relates lass::prim::Plane3D
57 * @relates lass::prim::LineSegment3D
58 *
59 * @param plane [in] the plane
60 * @param lineSegment [in] the line segment
61 * @param t [out] the parameter of the intersection point > @a tMin.
62 * @param tMin [in] the minimum t that may be returned as valid intersection.
63 * @return @arg rNone no intersections found
64 * @a t is not assigned.
65 * @arg rOne exactly one intersection found
66 * @a t represents it.
67 * @arg rInfinite infinite many intersections found (segment is coincident with plane),
68 * @a t is not assigned.
69 * @arg rInvalid @a plane or @a lineSegment is invalid, no intersection.
70 * @a t is not assigned.
71 */
72template<typename T, class EPPlane, class NPPlane, class PPRay>
74 const Plane3D<T, EPPlane, NPPlane>& plane, const LineSegment3D<T, PPRay>& lineSegment,
75 T& t)
76{
77 typedef typename Vector3D<T>::TValue TValue;
78 typedef typename Vector3D<T>::TNumTraits TNumTraits;
79
80 if (!plane.isValid())
81 {
82 return rInvalid;
83 }
84
85 const TValue eTail = plane.equation(lineSegment.tail());
86 const TValue eHead = plane.equation(lineSegment.head());
87
88 if (eTail == eHead)
89 {
90 return eTail == TNumTraits::zero ? rInfinite : rNone;
91 }
92 else
93 {
94 // find candidate of intersection.
95 const TValue tCandidate = eTail / (eTail - eHead);
96 if (tCandidate >= TNumTraits::zero && tCandidate <= TNumTraits::one)
97 {
98 t = tCandidate;
99 return rOne;
100 }
101 return rNone;
102 }
103}
104
105/** reflect a linesegment in a plane.
106 * @relates lass::prim::LineSegment3D
107 * @relates lass::prim::Plane3D
108 *
109 * @param plane [in] the reflection plane
110 * @param lineSegment [in] the line segment to be reflected
111 * @return the reflected line segment
112 */
113template <typename T, class EP, class NP, class PP>
115 const Plane3D<T, EP, NP>& plane, const LineSegment3D<T, PP>& lineSegment)
116{
117 return LineSegment3D<T, PP>(plane.reflect(lineSegment.tail()), plane.reflect(lineSegment.head()));
118}
119
120/** project a linesegment on a plane.
121 * @relates lass::prim::LineSegment3D
122 * @relates lass::prim::Plane3D
123 *
124 * @param plane [in] the projection plane
125 * @param lineSegment [in] the line segment to be projected
126 * @return the projected line segment
127 */
128template <typename T, class EP, class NP, class PP>
130 const Plane3D<T, EP, NP>& plane, const LineSegment3D<T, PP>& lineSegment)
131{
132 return LineSegment3D<T, PP>(plane.project(lineSegment.tail()), plane.project(lineSegment.head()));
133}
134
135}
136}
137
138#endif
139
140// EOF
Result intersect(const Plane3D< T, EPPlane, NPPlane > &plane, const LineSegment3D< T, PPRay > &lineSegment, T &t)
Find the intersection of a plane and line segment by their parameter t on the ray.
const TValue t(const TPoint &iPoint) const
A 3D hyper plane.
Definition plane_3d.h:361
LineSegment3D< T, PP > reflect(const Plane3D< T, EP, NP > &plane, const LineSegment3D< T, PP > &lineSegment)
reflect a linesegment in a plane.
LineSegment3D< T, PP > project(const Plane3D< T, EP, NP > &plane, const LineSegment3D< T, PP > &lineSegment)
project a linesegment on a plane.
const TValue equation(const TPoint &iPoint) const
Return value of point in equation.
bool isValid() const
return true if plane is a valid plane (no normal or direction vectors that are zero).
set of geometrical primitives
Definition aabb_2d.h:81
Result
meta information on the result you have from an operation like an intersection ...
Definition result.h:74
@ rInfinite
there are infinite many solutions, output arguments are meaningless
Definition result.h:79
@ rInvalid
0 is an invalid value, nothing is known.
Definition result.h:75
@ rNone
operation has no answer, output arguments are meaningless
Definition result.h:76
@ rOne
there's exactly one answer, 1 output argument contains the answer
Definition result.h:77
Library for Assembled Shared Sources.
Definition config.h:53