GteIntrSegment3Capsule3.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 
13 
14 // The queries consider the capsule to be a solid.
15 //
16 // The test-intersection queries are based on distance computations.
17 
18 namespace gte
19 {
20 
21 template <typename Real>
22 class TIQuery<Real, Segment3<Real>, Capsule3<Real>>
23 {
24 public:
25  struct Result
26  {
27  bool intersect;
28  };
29 
30  Result operator()(Segment3<Real> const& segment,
31  Capsule3<Real> const& capsule);
32 };
33 
34 template <typename Real>
35 class FIQuery<Real, Segment3<Real>, Capsule3<Real>>
36  :
37  public FIQuery<Real, Line3<Real>, Capsule3<Real>>
38 {
39 public:
40  struct Result
41  :
42  public FIQuery<Real, Line3<Real>, Capsule3<Real>>::Result
43  {
44  // No additional information to compute.
45  };
46 
47  Result operator()(Segment3<Real> const& segment,
48  Capsule3<Real> const& capsule);
49 
50 protected:
51  void DoQuery(Vector3<Real> const& segOrigin,
52  Vector3<Real> const& segDirection, Real segExtent,
53  Capsule3<Real> const& capsule, Result& result);
54 };
55 
56 
57 template <typename Real>
60  Segment3<Real> const& segment, Capsule3<Real> const& capsule)
61 {
62  Result result;
64  auto ssResult = ssQuery(segment, capsule.segment);
65  result.intersect = (ssResult.distance <= capsule.radius);
66  return result;
67 }
68 
69 template <typename Real>
72  Segment3<Real> const& segment, Capsule3<Real> const& capsule)
73 {
74  Vector3<Real> segOrigin, segDirection;
75  Real segExtent;
76  segment.GetCenteredForm(segOrigin, segDirection, segExtent);
77 
78  Result result;
79  DoQuery(segOrigin, segDirection, segExtent, capsule, result);
80  for (int i = 0; i < result.numIntersections; ++i)
81  {
82  result.point[i] = segOrigin + result.parameter[i] * segDirection;
83  }
84  return result;
85 }
86 
87 template <typename Real>
89  Vector3<Real> const& segOrigin, Vector3<Real> const& segDirection,
90  Real segExtent, Capsule3<Real> const& capsule, Result& result)
91 {
92  FIQuery<Real, Line3<Real>, Capsule3<Real>>::DoQuery(segOrigin,
93  segDirection, capsule, result);
94 
95  if (result.intersect)
96  {
97  // The line containing the segment intersects the capsule; the
98  // t-interval is [t0,t1]. The segment intersects the capsule as
99  // long as [t0,t1] overlaps the segment t-interval
100  // [-segExtent,+segExtent].
101  std::array<Real, 2> segInterval = { -segExtent, segExtent };
102  FIQuery<Real, std::array<Real, 2>, std::array<Real, 2>> iiQuery;
103  auto iiResult = iiQuery(result.parameter, segInterval);
104  if (iiResult.intersect)
105  {
106  result.numIntersections = iiResult.numIntersections;
107  result.parameter = iiResult.overlap;
108  }
109  else
110  {
111  result.intersect = false;
112  result.numIntersections = 0;
113  }
114  }
115 }
116 
117 
118 }
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