GteIntrSegment3Cylinder3.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>
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, Segment3<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()(Segment3<Real> const& segment,
33  Cylinder3<Real> const& cylinder);
34 
35 protected:
36  void DoQuery(Vector3<Real> const& segOrigin,
37  Vector3<Real> const& segDirection, Real segExtent,
38  Cylinder3<Real> const& cylinder, Result& result);
39 };
40 
41 
42 template <typename Real>
45  Segment3<Real> const& segment, Cylinder3<Real> const& cylinder)
46 {
47  Vector3<Real> segOrigin, segDirection;
48  Real segExtent;
49  segment.GetCenteredForm(segOrigin, segDirection, segExtent);
50 
51  Result result;
52  DoQuery(segOrigin, segDirection, segExtent, cylinder, result);
53  for (int i = 0; i < result.numIntersections; ++i)
54  {
55  result.point[i] = segOrigin + result.parameter[i] * segDirection;
56  }
57  return result;
58 }
59 
60 template <typename Real>
62  Vector3<Real> const& segOrigin, Vector3<Real> const& segDirection,
63  Real segExtent, Cylinder3<Real> const& cylinder, Result& result)
64 {
65  FIQuery<Real, Line3<Real>, Cylinder3<Real>>::DoQuery(segOrigin,
66  segDirection, cylinder, result);
67 
68  if (result.intersect)
69  {
70  // The line containing the segment intersects the cylinder; the
71  // t-interval is [t0,t1]. The segment intersects the cylinder as
72  // long as [t0,t1] overlaps the segment t-interval
73  // [-segExtent,+segExtent].
74  std::array<Real, 2> segInterval = { -segExtent, segExtent };
75  FIQuery<Real, std::array<Real, 2>, std::array<Real, 2>> iiQuery;
76  auto iiResult = iiQuery(result.parameter, segInterval);
77  if (iiResult.intersect)
78  {
79  result.numIntersections = iiResult.numIntersections;
80  result.parameter = iiResult.overlap;
81  }
82  else
83  {
84  result.intersect = false;
85  result.numIntersections = 0;
86  }
87  }
88 }
89 
90 
91 }
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