GteIntrSegment3Plane3.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/GteSegment.h>
12 
13 namespace gte
14 {
15 
16 template <typename Real>
17 class TIQuery<Real, Segment3<Real>, Plane3<Real>>
18 {
19 public:
20  struct Result
21  {
22  bool intersect;
23  };
24 
25  Result operator()(Segment3<Real> const& segment,
26  Plane3<Real> const& plane);
27 };
28 
29 template <typename Real>
30 class FIQuery<Real, Segment3<Real>, Plane3<Real>>
31  :
32  public FIQuery<Real, Line3<Real>, Plane3<Real>>
33 {
34 public:
35  struct Result
36  :
37  public FIQuery<Real, Line3<Real>, Plane3<Real>>::Result
38  {
39  // No additional information to compute.
40  };
41 
42  Result operator()(Segment3<Real> const& segment,
43  Plane3<Real> const& plane);
44 
45 protected:
46  void DoQuery(Vector3<Real> const& segOrigin,
47  Vector3<Real> const& segDirection, Real segExtent,
48  Plane3<Real> const& plane, Result& result);
49 };
50 
51 
52 template <typename Real>
55  Segment3<Real> const& segment, Plane3<Real> const& plane)
56 {
57  Result result;
58 
59  // Compute the (signed) distance from the segment endpoints to the plane.
61  Real sdistance0 = vpQuery(segment.p[0], plane).signedDistance;
62  if (sdistance0 == (Real)0)
63  {
64  // Endpoint p[0] is on the plane.
65  result.intersect = true;
66  return result;
67  }
68 
69  Real sdistance1 = vpQuery(segment.p[1], plane).signedDistance;
70  if (sdistance1 == (Real)0)
71  {
72  // Endpoint p[1] is on the plane.
73  result.intersect = true;
74  return result;
75  }
76 
77  // Test whether the segment transversely intersects the plane.
78  result.intersect = (sdistance0 * sdistance1 < (Real)0);
79  return result;
80 }
81 
82 template <typename Real>
85  Segment3<Real> const& segment, Plane3<Real> const& plane)
86 {
87  Vector3<Real> segOrigin, segDirection;
88  Real segExtent;
89  segment.GetCenteredForm(segOrigin, segDirection, segExtent);
90 
91  Result result;
92  DoQuery(segOrigin, segDirection, segExtent, plane, result);
93  if (result.intersect)
94  {
95  result.point = segOrigin + result.parameter * segDirection;
96  }
97  return result;
98 }
99 
100 template <typename Real>
102  Vector3<Real> const& segOrigin, Vector3<Real> const& segDirection,
103  Real segExtent, Plane3<Real> const& plane, Result& result)
104 {
105  FIQuery<Real, Line3<Real>, Plane3<Real>>::DoQuery(segOrigin,
106  segDirection, plane, result);
107  if (result.intersect)
108  {
109  // The line intersects the plane in a point that might not be on the
110  // segment.
111  if (std::abs(result.parameter) > segExtent)
112  {
113  result.intersect = false;
114  result.numIntersections = 0;
115  }
116  }
117 }
118 
119 
120 }
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
Definition: GteBSNumber.h:966
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