GteIntrSegment2Circle2.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 circle to be a solid (disk).
15 
16 namespace gte
17 {
18 
19 template <typename Real>
20 class TIQuery<Real, Segment2<Real>, Circle2<Real>>
21 {
22 public:
23  struct Result
24  {
25  bool intersect;
26  };
27 
28  Result operator()(Segment2<Real> const& segment,
29  Circle2<Real> const& circle);
30 };
31 
32 template <typename Real>
33 class FIQuery<Real, Segment2<Real>, Circle2<Real>>
34  :
35  public FIQuery<Real, Line2<Real>, Circle2<Real>>
36 {
37 public:
38  struct Result
39  :
40  public FIQuery<Real, Line2<Real>, Circle2<Real>>::Result
41  {
42  // No additional information to compute.
43  };
44 
45  Result operator()(Segment2<Real> const& segment,
46  Circle2<Real> const& circle);
47 
48 protected:
49  void DoQuery(Vector2<Real> const& segyOrigin,
50  Vector2<Real> const& segyDirection, Real segExtent,
51  Circle2<Real> const& circle, Result& result);
52 };
53 
54 
55 template <typename Real>
58  Segment2<Real> const& segment, Circle2<Real> const& circle)
59 {
60  Result result;
62  result.intersect = scQuery(segment, circle).intersect;
63  return result;
64 }
65 
66 template <typename Real>
69  Segment2<Real> const& segment, Circle2<Real> const& circle)
70 {
71  Vector2<Real> segOrigin, segDirection;
72  Real segExtent;
73  segment.GetCenteredForm(segOrigin, segDirection, segExtent);
74 
75  Result result;
76  DoQuery(segOrigin, segDirection, segExtent, circle, result);
77  for (int i = 0; i < result.numIntersections; ++i)
78  {
79  result.point[i] = segOrigin + result.parameter[i] * segDirection;
80  }
81  return result;
82 }
83 
84 template <typename Real>
86  Vector2<Real> const& segOrigin, Vector2<Real> const& segDirection,
87  Real segExtent, Circle2<Real> const& circle, Result& result)
88 {
89  FIQuery<Real, Line2<Real>, Circle2<Real>>::DoQuery(segOrigin,
90  segDirection, circle, result);
91 
92  if (result.intersect)
93  {
94  // The line containing the segment intersects the disk; the t-interval
95  // is [t0,t1]. The segment intersects the disk as long as [t0,t1]
96  // overlaps the segment t-interval [-segExtent,+segExtent].
97  std::array<Real, 2> segInterval = { -segExtent, segExtent };
98  FIQuery<Real, std::array<Real, 2>, std::array<Real, 2>> iiQuery;
99  auto iiResult = iiQuery(result.parameter, segInterval);
100  result.intersect = iiResult.intersect;
101  result.numIntersections = iiResult.numIntersections;
102  result.parameter = iiResult.overlap;
103  }
104 }
105 
106 
107 }
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