GteIntrRay3Cylinder3.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 cylinder to be a solid.
15 
16 namespace gte
17 {
18 
19 template <typename Real>
20 class FIQuery<Real, Ray3<Real>, Cylinder3<Real>>
21  :
22  public FIQuery<Real, Line3<Real>, Cylinder3<Real>>
23 {
24 public:
25  struct Result
26  :
27  public FIQuery<Real, Line3<Real>, Cylinder3<Real>>::Result
28  {
29  // No additional information to compute.
30  };
31 
32  Result operator()(Ray3<Real> const& ray, Cylinder3<Real> const& cylinder);
33 
34 protected:
35  void DoQuery(Vector3<Real> const& rayOrigin,
36  Vector3<Real> const& rayDirection, Cylinder3<Real> const& cylinder,
37  Result& result);
38 };
39 
40 
41 template <typename Real>
44  Ray3<Real> const& ray, Cylinder3<Real> const& cylinder)
45 {
46  Result result;
47  DoQuery(ray.origin, ray.direction, cylinder, result);
48  for (int i = 0; i < result.numIntersections; ++i)
49  {
50  result.point[i] = ray.origin + result.parameter[i] * ray.direction;
51  }
52  return result;
53 }
54 
55 template <typename Real>
57  Vector3<Real> const& rayOrigin, Vector3<Real> const& rayDirection,
58  Cylinder3<Real> const& cylinder, Result& result)
59 {
60  FIQuery<Real, Line3<Real>, Cylinder3<Real>>::DoQuery(rayOrigin,
61  rayDirection, cylinder, result);
62 
63  if (result.intersect)
64  {
65  // The line containing the ray intersects the cylinder; the t-interval
66  // is [t0,t1]. The ray intersects the cylinder as long as [t0,t1]
67  // overlaps the ray t-interval [0,+infinity).
68  std::array<Real, 2> rayInterval =
69  { (Real)0, std::numeric_limits<Real>::max() };
70  FIQuery<Real, std::array<Real, 2>, std::array<Real, 2>> iiQuery;
71  auto iiResult = iiQuery(result.parameter, rayInterval);
72  if (iiResult.intersect)
73  {
74  result.numIntersections = iiResult.numIntersections;
75  result.parameter = iiResult.overlap;
76  }
77  else
78  {
79  result.intersect = false;
80  result.numIntersections = 0;
81  }
82  }
83 }
84 
85 
86 }
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