GteIntrRay3Cone3.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 // The queries consider the cone to be single sided and solid.
14 
15 namespace gte
16 {
17 
18 template <typename Real>
19 class FIQuery<Real, Ray3<Real>, Cone3<Real>>
20  :
21  public FIQuery<Real, Line3<Real>, Cone3<Real>>
22 {
23 public:
24  struct Result
25  :
26  public FIQuery<Real, Line3<Real>, Cone3<Real>>::Result
27  {
28  // No additional information to compute.
29  };
30 
31  Result operator()(Ray3<Real> const& ray, Cone3<Real> const& cone);
32 
33 protected:
34  void DoQuery(Vector3<Real> const& rayOrigin,
35  Vector3<Real> const& rayDirection, Cone3<Real> const& cone,
36  Result& result);
37 };
38 
39 
40 template <typename Real>
41 typename FIQuery<Real, Ray3<Real>, Cone3<Real>>::Result
43  Cone3<Real> const& cone)
44 {
45  Result result;
46  DoQuery(ray.origin, ray.direction, cone, result);
47  switch (result.type)
48  {
49  case 1: // point
50  result.point[0] = ray.origin + result.parameter[0] * ray.direction;
51  result.point[1] = result.point[0];
52  break;
53  case 2: // segment
54  result.point[0] = ray.origin + result.parameter[0] * ray.direction;
55  result.point[1] = ray.origin + result.parameter[1] * ray.direction;
56  break;
57  case 3: // ray
58  result.point[0] = ray.origin + result.parameter[0] * ray.direction;
59  result.point[1] = ray.direction;
60  break;
61  default: // no intersection
62  break;
63  }
64  return result;
65 }
66 
67 template <typename Real>
69  Vector3<Real> const& rayOrigin, Vector3<Real> const& rayDirection,
70  Cone3<Real> const& cone, Result& result)
71 {
72  FIQuery<Real, Line3<Real>, Cone3<Real>>::DoQuery(rayOrigin,
73  rayDirection, cone, result);
74 
75  if (result.intersect)
76  {
77  // The line containing the ray intersects the cone; the t-interval
78  // is [t0,t1]. The ray intersects the cone as long as [t0,t1]
79  // overlaps the ray t-interval [0,+infinity).
80  std::array<Real, 2> rayInterval = {
81  (Real)0, std::numeric_limits<Real>::max() };
83  auto iiResult = iiQuery(result.parameter, rayInterval);
84  if (iiResult.intersect)
85  {
86  result.parameter = iiResult.overlap;
87  if (result.parameter[1] < std::numeric_limits<Real>::max())
88  {
89  result.type = iiResult.numIntersections;
90  }
91  else
92  {
93  result.type = 3;
94  }
95  }
96  else
97  {
98  result.intersect = false;
99  result.type = 0;
100  }
101  }
102 }
103 
104 
105 }
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