GteIntrCircle2Arc2.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, Circle2<Real>, Arc2<Real>>
18 {
19 public:
20  struct Result
21  {
22  bool intersect;
23 
24  // The number of intersections is 0, 1, 2, or maxInt =
25  // std::numeric_limits<int>::max(). When 1, the arc and circle
26  // intersect in a single point. When 2, the arc is not on the circle
27  // and they intersect in two points. When maxInt, the arc is on the
28  // circle.
30 
31  // Valid only when numIntersections = 1 or 2.
32  Vector2<Real> point[2];
33 
34  // Valid only when numIntersections = maxInt.
36  };
37 
38  Result operator()(Circle2<Real> const& circle, Arc2<Real> const& arc);
39 };
40 
41 
42 template <typename Real>
43 typename FIQuery<Real, Circle2<Real>, Arc2<Real>>::Result
45  Circle2<Real> const& circle, Arc2<Real> const& arc)
46 {
47  Result result;
48 
49  Circle2<Real> circleOfArc(arc.center, arc.radius);
51  auto ccResult = ccQuery(circle, circleOfArc);
52  if (!ccResult.intersect)
53  {
54  result.intersect = false;
55  result.numIntersections = 0;
56  return result;
57  }
58 
59  if (ccResult.numIntersections == std::numeric_limits<int>::max())
60  {
61  // The arc is on the circle.
62  result.intersect = true;
63  result.numIntersections = std::numeric_limits<int>::max();
64  result.arc = arc;
65  return result;
66  }
67 
68  // Test whether circle-circle intersection points are on the arc.
69  for (int i = 0; i < ccResult.numIntersections; ++i)
70  {
71  result.numIntersections = 0;
72  if (arc.Contains(ccResult.point[i]))
73  {
74  result.point[result.numIntersections++] = ccResult.point[i];
75  result.intersect = true;
76  }
77  }
78  return result;
79 }
80 
81 
82 }
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