GteIntrLine3Plane3.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
11 #include <Mathematics/GteLine.h>
12 #include <Mathematics/GteFIQuery.h>
13 #include <Mathematics/GteTIQuery.h>
14 #include <limits>
15 
16 namespace gte
17 {
18 
19 template <typename Real>
20 class TIQuery<Real, Line3<Real>, Plane3<Real>>
21 {
22 public:
23  struct Result
24  {
25  bool intersect;
26  };
27 
28  Result operator()(Line3<Real> const& line, Plane3<Real> const& plane);
29 };
30 
31 template <typename Real>
32 class FIQuery<Real, Line3<Real>, Plane3<Real>>
33 {
34 public:
35  struct Result
36  {
37  bool intersect;
38 
39  // The number of intersections is 0 (no intersection), 1 (linear
40  // component and plane intersect in a point), or
41  // std::numeric_limits<int>::max() (linear component is on the plane).
42  // If the linear component is on the plane, 'point' component's
43  // origin and 'parameter' is zero.
45  Real parameter;
47  };
48 
49  Result operator()(Line3<Real> const& line, Plane3<Real> const& plane);
50 
51 protected:
52  void DoQuery(Vector3<Real> const& lineOrigin,
53  Vector3<Real> const& lineDirection, Plane3<Real> const& plane,
54  Result& result);
55 };
56 
57 
58 template <typename Real>
59 typename TIQuery<Real, Line3<Real>, Plane3<Real>>::Result
61  Line3<Real> const& line, Plane3<Real> const& plane)
62 {
63  Result result;
64 
65  Real DdN = Dot(line.direction, plane.normal);
66  if (DdN != (Real)0)
67  {
68  // The line is not parallel to the plane, so they must intersect.
69  result.intersect = true;
70  }
71  else
72  {
73  // The line and plane are parallel.
75  result.intersect = (vpQuery(line.origin, plane).distance == (Real)0);
76  }
77 
78  return result;
79 }
80 
81 template <typename Real>
82 typename FIQuery<Real, Line3<Real>, Plane3<Real>>::Result
84  Line3<Real> const& line, Plane3<Real> const& plane)
85 {
86  Result result;
87  DoQuery(line.origin, line.direction, plane, result);
88  if (result.intersect)
89  {
90  result.point = line.origin + result.parameter * line.direction;
91  }
92  return result;
93 }
94 
95 template <typename Real>
97  Vector3<Real> const& lineOrigin, Vector3<Real> const& lineDirection,
98  Plane3<Real> const& plane, Result& result)
99 {
100  Real DdN = Dot(lineDirection, plane.normal);
102  auto vpResult = vpQuery(lineOrigin, plane);
103 
104  if (DdN != (Real)0)
105  {
106  // The line is not parallel to the plane, so they must intersect.
107  result.intersect = true;
108  result.numIntersections = 1;
109  result.parameter = -vpResult.signedDistance / DdN;
110  }
111  else
112  {
113  // The line and plane are parallel. Determine whether the line is on
114  // the plane.
115  if (vpResult.distance == (Real)0)
116  {
117  // The line is coincident with the plane, so choose t = 0 for the
118  // parameter.
119  result.intersect = true;
120  result.numIntersections = std::numeric_limits<int>::max();
121  result.parameter = (Real)0;
122  }
123  else
124  {
125  // The line is not on the plane.
126  result.intersect = false;
127  result.numIntersections = 0;
128  }
129  }
130 }
131 
132 
133 }
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Vector< N, Real > normal
Definition: GteHyperplane.h:40
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
GLuint64EXT * result
Definition: glext.h:10003


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00