GteArc2.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/GteVector2.h>
11 
12 namespace gte
13 {
14 
15 // The circle containing the arc is represented as |X-C| = R where C is the
16 // center and R is the radius. The arc is defined by two points end0 and end1
17 // on the circle so that end1 is obtained from end0 by traversing
18 // counterclockwise. The application is responsible for ensuring that end0
19 // and end1 are on the circle and that they are properly ordered.
20 
21 template <typename Real>
22 class Arc2
23 {
24 public:
25  // Construction and destruction. The default constructor sets the center
26  // to (0,0), radius to 1, end0 to (1,0), and end1 to (0,1).
27  Arc2();
28  Arc2(Vector2<Real> const& inCenter, Real inRadius,
29  Vector2<Real>const& inEnd0, Vector2<Real>const & inEnd1);
30 
31  // Test whether P is on the arc. The application must ensure that P is on
32  // the circle; that is, |P-C| = R. This test works for any angle between
33  // B-C and A-C, not just those between 0 and pi radians.
34  bool Contains(Vector2<Real> const& p) const;
35 
37  Real radius;
39 
40 public:
41  // Comparisons to support sorted containers.
42  bool operator==(Arc2 const& arc) const;
43  bool operator!=(Arc2 const& arc) const;
44  bool operator< (Arc2 const& arc) const;
45  bool operator<=(Arc2 const& arc) const;
46  bool operator> (Arc2 const& arc) const;
47  bool operator>=(Arc2 const& arc) const;
48 };
49 
50 
51 template <typename Real>
53  :
54  center(Vector2<Real>::Zero()),
55  radius((Real)1)
56 {
57  end[0] = Vector2<Real>::Unit(0);
58  end[1] = Vector2<Real>::Unit(1);
59 }
60 
61 template <typename Real>
62 Arc2<Real>::Arc2(Vector2<Real> const& inCenter, Real inRadius,
63  Vector2<Real>const& inEnd0, Vector2<Real>const & inEnd1)
64  :
65  center(inCenter),
66  radius(inRadius)
67 {
68  end[0] = inEnd0;
69  end[1] = inEnd1;
70 }
71 
72 template <typename Real>
74 {
75  // Assert: |P-C| = R where P is the input point, C is the circle center,
76  // and R is the circle radius. For P to be on the arc from A to B, it
77  // must be on the side of the plane containing A with normal N = Perp(B-A)
78  // where Perp(u,v) = (v,-u).
79 
80  Vector2<Real> diffPE0 = p - end[0];
81  Vector2<Real> diffE1E0 = end[1] - end[0];
82  Real dotPerp = DotPerp(diffPE0, diffE1E0);
83  return dotPerp >= (Real)0;
84 }
85 
86 template <typename Real>
87 bool Arc2<Real>::operator==(Arc2 const& arc) const
88 {
89  return center == arc.center && radius == arc.radius
90  && end[0] == arc.end[0] && end[1] == arc.end[1];
91 }
92 
93 template <typename Real>
94 bool Arc2<Real>::operator!=(Arc2 const& arc) const
95 {
96  return !operator==(arc);
97 }
98 
99 template <typename Real>
100 bool Arc2<Real>::operator<(Arc2 const& arc) const
101 {
102  if (center < arc.center)
103  {
104  return true;
105  }
106 
107  if (center > arc.center)
108  {
109  return false;
110  }
111 
112  if (radius < arc.radius)
113  {
114  return true;
115  }
116 
117  if (radius > arc.radius)
118  {
119  return false;
120  }
121 
122  if (end[0] < arc.end[0])
123  {
124  return true;
125  }
126 
127  if (end[0] > arc.end[0])
128  {
129  return false;
130  }
131 
132  return end[1] < arc.end[1];
133 }
134 
135 template <typename Real>
136 bool Arc2<Real>::operator<=(Arc2 const& arc) const
137 {
138  return operator<(arc) || operator==(arc);
139 }
140 
141 template <typename Real>
142 bool Arc2<Real>::operator>(Arc2 const& arc) const
143 {
144  return !operator<=(arc);
145 }
146 
147 template <typename Real>
148 bool Arc2<Real>::operator>=(Arc2 const& arc) const
149 {
150  return !operator<(arc);
151 }
152 
153 
154 }
bool operator<(Arc2 const &arc) const
Definition: GteArc2.h:100
bool operator<=(Arc2 const &arc) const
Definition: GteArc2.h:136
Real radius
Definition: GteArc2.h:37
GLuint GLuint end
Definition: glcorearb.h:470
Arc2()
Definition: GteArc2.h:52
Real DotPerp(Vector2< Real > const &v0, Vector2< Real > const &v1)
Definition: GteVector2.h:117
bool operator>=(Arc2 const &arc) const
Definition: GteArc2.h:148
bool operator>(Arc2 const &arc) const
Definition: GteArc2.h:142
Vector2< Real > center
Definition: GteArc2.h:36
Vector2< Real > end[2]
Definition: GteArc2.h:38
bool operator!=(Arc2 const &arc) const
Definition: GteArc2.h:94
bool operator==(Arc2 const &arc) const
Definition: GteArc2.h:87
GLfloat GLfloat p
Definition: glext.h:11668
bool Contains(Vector2< Real > const &p) const
Definition: GteArc2.h:73
static Vector Unit(int d)


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59