GteIntrArc2Arc2.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/GteArc2.h>
12 
13 namespace gte
14 {
15 
16 template <typename Real>
17 class FIQuery<Real, Arc2<Real>, Arc2<Real>>
18 {
19 public:
20  // The possible 'configuration' in Result are listed as an enumeration.
21  // The valid array elements are listed in the comments.
22  enum
23  {
26  NONCOCIRCULAR_TWO_POINTS, // point[0], point[1]
27  COCIRCULAR_ONE_POINT, // point[0]
28  COCIRCULAR_TWO_POINTS, // point[0], point[1]
29  COCIRCULAR_ONE_POINT_ONE_ARC, // point[0], arc[0]
30  COCIRCULAR_ONE_ARC, // arc[0]
31  COCIRCULAR_TWO_ARCS // arc[0], arc[1]
32  };
33 
34  struct Result
35  {
36  bool intersect; // 'true' iff configuration != NO_INTERSECTION
37  int configuration; // one of the enumerations listed previously
38  Vector2<Real> point[2];
39  Arc2<Real> arc[2];
40  };
41 
42  Result operator()(Arc2<Real> const& arc0, Arc2<Real> const& arc1);
43 };
44 
45 
46 template <typename Real>
47 typename FIQuery<Real, Arc2<Real>, Arc2<Real>>::Result
48 FIQuery<Real, Arc2<Real>, Arc2<Real>>::operator()(Arc2<Real> const& arc0, Arc2<Real> const& arc1)
49 {
50  // Assume initially there are no intersections. If we find at least one
51  // intersection, we will set result.intersect to 'true'.
52  Result result;
53  result.intersect = false;
54 
55  Circle2<Real> circle0(arc0.center, arc0.radius);
56  Circle2<Real> circle1(arc1.center, arc1.radius);
58  auto ccResult = ccQuery(circle0, circle1);
59  if (!ccResult.intersect)
60  {
61  // The arcs do not intersect.
62  result.configuration = NO_INTERSECTION;
63  return result;
64  }
65 
66  if (ccResult.numIntersections == std::numeric_limits<int>::max())
67  {
68  // The arcs are cocircular. Determine whether they overlap. Let
69  // arc0 be <A0,A1> and arc1 be <B0,B1>. The points are ordered
70  // counterclockwise around the circle of the arc.
71  if (arc1.Contains(arc0.end[0]))
72  {
73  result.intersect = true;
74  if (arc1.Contains(arc0.end[1]))
75  {
76  if (arc0.Contains(arc1.end[0]) && arc0.Contains(arc1.end[1]))
77  {
78  // arc0 and arc1 overlap in two disjoint subsets.
79  if (arc0.end[0] != arc1.end[1])
80  {
81  if (arc1.end[0] != arc0.end[1])
82  {
83  // The arcs overlap in two disjoint subarcs, each
84  // of positive subtended angle: <A0,B1>, <A1,B0>
85  result.configuration = COCIRCULAR_TWO_ARCS;
86  result.arc[0] = Arc2<Real>(arc0.center, arc0.radius, arc0.end[0], arc1.end[1]);
87  result.arc[1] = Arc2<Real>(arc0.center, arc0.radius, arc1.end[0], arc0.end[1]);
88  }
89  else // B0 = A1
90  {
91  // The intersection is a point {A1} and an
92  // arc <A0,B1>.
93  result.configuration = COCIRCULAR_ONE_POINT_ONE_ARC;
94  result.point[0] = arc0.end[1];
95  result.arc[0] = Arc2<Real>(arc0.center, arc0.radius, arc0.end[0], arc1.end[1]);
96  }
97  }
98  else // A0 = B1
99  {
100  if (arc1.end[0] != arc0.end[1])
101  {
102  // The intersection is a point {A0} and an
103  // arc <A1,B0>.
104  result.configuration = COCIRCULAR_ONE_POINT_ONE_ARC;
105  result.point[0] = arc0.end[0];
106  result.arc[0] = Arc2<Real>(arc0.center, arc0.radius, arc1.end[0], arc0.end[1]);
107  }
108  else
109  {
110  // The arcs shared endpoints, so the union is a circle.
111  result.configuration = COCIRCULAR_TWO_POINTS;
112  result.point[0] = arc0.end[0];
113  result.point[1] = arc0.end[1];
114  }
115  }
116  }
117  else
118  {
119  // Arc0 inside arc1, <B0,A0,A1,B1>.
120  result.configuration = COCIRCULAR_ONE_ARC;
121  result.arc[0] = arc0;
122  }
123  }
124  else
125  {
126  if (arc0.end[0] != arc1.end[1])
127  {
128  // Arc0 and arc1 overlap, <B0,A0,B1,A1>.
129  result.configuration = COCIRCULAR_ONE_ARC;
130  result.arc[0] = Arc2<Real>(arc0.center, arc0.radius, arc0.end[0], arc1.end[1]);
131  }
132  else
133  {
134  // Arc0 and arc1 share endpoint, <B0,A0,B1,A1>, A0 = B1.
135  result.configuration = COCIRCULAR_ONE_POINT;
136  result.point[0] = arc0.end[0];
137  }
138  }
139  return result;
140  }
141 
142  if (arc1.Contains(arc0.end[1]))
143  {
144  result.intersect = true;
145  if (arc0.end[1] != arc1.end[0])
146  {
147  // Arc0 and arc1 overlap in a single arc, <A0,B0,A1,B1>.
148  result.configuration = COCIRCULAR_ONE_ARC;
149  result.arc[0] = Arc2<Real>(arc0.center, arc0.radius, arc1.end[0], arc0.end[1]);
150  }
151  else
152  {
153  // Arc0 and arc1 share endpoint, <A0,B0,A1,B1>, B0 = A1.
154  result.configuration = COCIRCULAR_ONE_POINT;
155  result.point[0] = arc1.end[0];
156  }
157  return result;
158  }
159 
160  if (arc0.Contains(arc1.end[0]))
161  {
162  // Arc1 inside arc0, <A0,B0,B1,A1>.
163  result.intersect = true;
164  result.configuration = COCIRCULAR_ONE_ARC;
165  result.arc[0] = arc1;
166  }
167  else
168  {
169  // Arcs do not overlap, <A0,A1,B0,B1>.
170  result.configuration = NO_INTERSECTION;
171  }
172  return result;
173  }
174 
175  // Test whether circle-circle intersection points are on the arcs.
176  int numIntersections = 0;
177  for (int i = 0; i < ccResult.numIntersections; ++i)
178  {
179  if (arc0.Contains(ccResult.point[i]) && arc1.Contains(ccResult.point[i]))
180  {
181  result.point[numIntersections++] = ccResult.point[i];
182  result.intersect = true;
183  }
184  }
185 
186  if (numIntersections == 2)
187  {
188  result.configuration = NONCOCIRCULAR_TWO_POINTS;
189  }
190  else if (numIntersections == 1)
191  {
192  result.configuration = NONCOCIRCULAR_ONE_POINT;
193  }
194  else
195  {
196  result.configuration = NO_INTERSECTION;
197  }
198 
199  return result;
200 }
201 
202 
203 }
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