GteIntrSegment3Cone3.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>
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, Segment3<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()(Segment3<Real> const& segment, Cone3<Real> const& cone);
32 
33 protected:
34  void DoQuery(Vector3<Real> const& segOrigin,
35  Vector3<Real> const& segDirection, Real segExtent,
36  Cone3<Real> const& cone, Result& result);
37 };
38 
39 
40 template <typename Real>
43  Segment3<Real> const& segment, Cone3<Real> const& cone)
44 {
45  Vector3<Real> segOrigin, segDirection;
46  Real segExtent;
47  segment.GetCenteredForm(segOrigin, segDirection, segExtent);
48 
49  Result result;
50  DoQuery(segOrigin, segDirection, segExtent, cone, result);
51  switch (result.type)
52  {
53  case 1: // point
54  result.point[0] = segOrigin + result.parameter[0] * segDirection;
55  result.point[1] = result.point[0];
56  break;
57  case 2: // segment
58  result.point[0] = segOrigin + result.parameter[0] * segDirection;
59  result.point[1] = segOrigin + result.parameter[1] * segDirection;
60  break;
61  default: // no intersection
62  break;
63  }
64  return result;
65 }
66 
67 template <typename Real>
69  Vector3<Real> const& segOrigin, Vector3<Real> const& segDirection,
70  Real segExtent, Cone3<Real> const& cone, Result& result)
71 {
72  FIQuery<Real, Line3<Real>, Cone3<Real>>::DoQuery(segOrigin,
73  segDirection, cone, result);
74 
75  if (result.intersect)
76  {
77  // The line containing the segment intersects the cone; the
78  // t-interval is [t0,t1]. The segment intersects the cone as
79  // long as [t0,t1] overlaps the segment t-interval
80  // [-segExtent,+segExtent].
81  std::array<Real, 2> segInterval = { -segExtent, segExtent };
83  auto iiResult = iiQuery(result.parameter, segInterval);
84  if (iiResult.intersect)
85  {
86  result.parameter = iiResult.overlap;
87  result.type = iiResult.numIntersections;
88  }
89  else
90  {
91  result.intersect = false;
92  result.type = 0;
93  }
94  }
95 }
96 
97 
98 }
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