GteIntrRay3Plane3.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 
10 #include <Mathematics/GteRay.h>
12 
13 namespace gte
14 {
15 
16 template <typename Real>
17 class TIQuery<Real, Ray3<Real>, Plane3<Real>>
18 {
19 public:
20  struct Result
21  {
22  bool intersect;
23  };
24 
25  Result operator()(Ray3<Real> const& ray, Plane3<Real> const& plane);
26 };
27 
28 template <typename Real>
29 class FIQuery<Real, Ray3<Real>, Plane3<Real>>
30  :
31  public FIQuery<Real, Line3<Real>, Plane3<Real>>
32 {
33 public:
34  struct Result
35  :
36  public FIQuery<Real, Line3<Real>, Plane3<Real>>::Result
37  {
38  // No additional information to compute.
39  };
40 
41  Result operator()(Ray3<Real> const& ray, Plane3<Real> const& plane);
42 
43 protected:
44  void DoQuery(Vector3<Real> const& rayOrigin,
45  Vector3<Real> const& rayDirection, Plane3<Real> const& plane,
46  Result& result);
47 };
48 
49 
50 template <typename Real>
51 typename TIQuery<Real, Ray3<Real>, Plane3<Real>>::Result
53  Ray3<Real> const& ray, Plane3<Real> const& plane)
54 {
55  Result result;
56 
57  // Compute the (signed) distance from the ray origin to the plane.
59  auto vpResult = vpQuery(ray.origin, plane);
60 
61  Real DdN = Dot(ray.direction, plane.normal);
62  if (DdN > (Real)0)
63  {
64  // The ray is not parallel to the plane and is directed toward the
65  // +normal side of the plane.
66  result.intersect = (vpResult.signedDistance <= (Real)0);
67  }
68  else if (DdN < (Real)0)
69  {
70  // The ray is not parallel to the plane and is directed toward the
71  // -normal side of the plane.
72  result.intersect = (vpResult.signedDistance >= (Real)0);
73  }
74  else
75  {
76  // The ray and plane are parallel.
77  result.intersect = (vpResult.distance == (Real)0);
78  }
79 
80  return result;
81 }
82 
83 template <typename Real>
84 typename FIQuery<Real, Ray3<Real>, Plane3<Real>>::Result
86  Ray3<Real> const& ray, Plane3<Real> const& plane)
87 {
88  Result result;
89  DoQuery(ray.origin, ray.direction, plane, result);
90  if (result.intersect)
91  {
92  result.point = ray.origin + result.parameter * ray.direction;
93  }
94  return result;
95 }
96 
97 template <typename Real>
99  Vector3<Real> const& rayOrigin, Vector3<Real> const& rayDirection,
100  Plane3<Real> const& plane, Result& result)
101 {
102  FIQuery<Real, Line3<Real>, Plane3<Real>>::DoQuery(rayOrigin,
103  rayDirection, plane, result);
104  if (result.intersect)
105  {
106  // The line intersects the plane in a point that might not be on the
107  // ray.
108  if (result.parameter < (Real)0)
109  {
110  result.intersect = false;
111  result.numIntersections = 0;
112  }
113  }
114 }
115 
116 
117 }
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
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