GteIntrLine2Ray2.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, Line2<Real>, Ray2<Real>>
18 {
19 public:
20  struct Result
21  {
22  bool intersect;
23 
24  // The number is 0 (no intersection), 1 (line and ray intersect in a
25  // single point) or std::numeric_limits<int>::max() (line and ray
26  // are collinear).
28  };
29 
30  Result operator()(Line2<Real> const& line, Ray2<Real> const& ray);
31 };
32 
33 template <typename Real>
34 class FIQuery<Real, Line2<Real>, Ray2<Real>>
35 {
36 public:
37  struct Result
38  {
39  bool intersect;
40 
41  // The number is 0 (no intersection), 1 (line and ray intersect in a
42  // single point) or std::numeric_limits<int>::max() (line and ray
43  // are collinear).
45 
46  // If numIntersections is 1, the intersection is
47  // point = line.origin + lineParameter[0] * line.direction
48  // = ray.origin + rayParameter[0] * ray.direction
49  // If numIntersections is maxInt, point is not valid but the
50  // intervals are
51  // lineParameter[] = { -maxReal, +maxReal }
52  // rayParameter[] = { 0, +maxReal }
53  Real lineParameter[2], rayParameter[2];
55  };
56 
57  Result operator()(Line2<Real> const& line, Ray2<Real> const& ray);
58 };
59 
60 
61 template <typename Real>
62 typename TIQuery<Real, Line2<Real>, Ray2<Real>>::Result
64  Line2<Real> const& line, Ray2<Real> const& ray)
65 {
66  Result result;
68  auto llResult = llQuery(line, Line2<Real>(ray.origin, ray.direction));
69  if (llResult.numIntersections == 1)
70  {
71  // Test whether the line-line intersection is on the ray.
72  if (llResult.line1Parameter[0] >= (Real)0)
73  {
74  result.intersect = true;
75  result.numIntersections = 1;
76  }
77  else
78  {
79  result.intersect = false;
80  result.numIntersections = 0;
81  }
82  }
83  else
84  {
85  result.intersect = llResult.intersect;
86  result.numIntersections = llResult.numIntersections;
87  }
88  return result;
89 }
90 
91 template <typename Real>
92 typename FIQuery<Real, Line2<Real>, Ray2<Real>>::Result
94  Line2<Real> const& line, Ray2<Real> const& ray)
95 {
96  Result result;
98  auto llResult = llQuery(line, Line2<Real>(ray.origin, ray.direction));
99  if (llResult.numIntersections == 1)
100  {
101  // Test whether the line-line intersection is on the ray.
102  if (llResult.line1Parameter[0] >= (Real)0)
103  {
104  result.intersect = true;
105  result.numIntersections = 1;
106  result.lineParameter[0] = llResult.line0Parameter[0];
107  result.rayParameter[0] = llResult.line1Parameter[0];
108  result.point = llResult.point;
109  }
110  else
111  {
112  result.intersect = false;
113  result.numIntersections = 0;
114  }
115  }
116  else if (llResult.numIntersections == std::numeric_limits<int>::max())
117  {
118  result.intersect = true;
119  result.numIntersections = std::numeric_limits<int>::max();
120  Real maxReal = std::numeric_limits<Real>::max();
121  result.lineParameter[0] = -maxReal;
122  result.lineParameter[1] = +maxReal;
123  result.rayParameter[0] = (Real)0;
124  result.rayParameter[1] = +maxReal;
125  }
126  else
127  {
128  result.intersect = false;
129  result.numIntersections = 0;
130  }
131  return result;
132 }
133 
134 
135 }
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