GteIntrRay2Triangle2.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>
13 
14 // The queries consider the triangle to be a solid.
15 
16 namespace gte
17 {
18 
19 template <typename Real>
20 class TIQuery<Real, Ray2<Real>, Triangle2<Real>>
21 {
22 public:
23  struct Result
24  {
25  bool intersect;
26  };
27 
28  Result operator()(Ray2<Real> const& ray, Triangle2<Real> const& triangle);
29 };
30 
31 template <typename Real>
32 class FIQuery<Real, Ray2<Real>, Triangle2<Real>>
33  :
34  public FIQuery<Real, Line2<Real>, Triangle2<Real>>
35 {
36 public:
37  struct Result
38  :
39  public FIQuery<Real, Line2<Real>, Triangle2<Real>>::Result
40  {
41  // No additional information to compute.
42  };
43 
44  Result operator()(Ray2<Real> const& ray, Triangle2<Real> const& triangle);
45 
46 protected:
47  void DoQuery(Vector2<Real> const& rayOrigin,
48  Vector2<Real> const& rayDirection, Triangle2<Real> const& triangle,
49  Result& result);
50 };
51 
52 
53 template <typename Real>
56  Ray2<Real> const& ray, Triangle2<Real> const& triangle)
57 {
58  Result result;
60  result.intersect = rtQuery(ray, triangle).intersect;
61  return result;
62 }
63 
64 template <typename Real>
67  Ray2<Real> const& ray, Triangle2<Real> const& triangle)
68 {
69  Result result;
70  DoQuery(ray.origin, ray.direction, triangle, result);
71  for (int i = 0; i < result.numIntersections; ++i)
72  {
73  result.point[i] = ray.origin + result.parameter[i] * ray.direction;
74  }
75  return result;
76 }
77 
78 template <typename Real>
80  Vector2<Real> const& rayOrigin, Vector2<Real> const& rayDirection,
81  Triangle2<Real> const& triangle, Result& result)
82 {
83  FIQuery<Real, Line2<Real>, Triangle2<Real>>::DoQuery(rayOrigin,
84  rayDirection, triangle, result);
85 
86  if (result.intersect)
87  {
88  // The line containing the ray intersects the disk; the t-interval is
89  // [t0,t1]. The ray intersects the disk as long as [t0,t1] overlaps
90  // the ray t-interval [0,+infinity).
91  std::array<Real, 2> rayInterval =
92  { (Real)0, std::numeric_limits<Real>::max() };
93  FIQuery<Real, std::array<Real, 2>, std::array<Real, 2>> iiQuery;
94  result.parameter = iiQuery(result.parameter, rayInterval).overlap;
95  }
96 }
97 
98 
99 }
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