GteSector2.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 
11 #include <Mathematics/GteVector2.h>
12 
13 namespace gte
14 {
15 
16 // A solid sector is the intersection of a disk and a 2D cone. The disk
17 // has center C, radius R, and contains points X for which |X-C| <= R. The
18 // 2D cone has vertex C, unit-length axis direction D, angle A in (0,pi)
19 // measured from D, and contains points X for which Dot(D,(X-C)/|X-C|) >= cos(A).
20 // Sector points X satisfy both inequality constraints.
21 
22 template <typename Real>
23 class Sector2
24 {
25 public:
26  // Construction and destruction. The default constructor sets the vertex
27  // to (0,0), radius to 1, axis direction to (1,0), and angle to pi,
28  // all of which define a disk.
29  Sector2();
30  Sector2(Vector2<Real> const& inVertex, Real inRadius,
31  Vector2<Real> const& inDirection, Real inAngle);
32 
33  // Set the angle and cos(angle) simultaneously.
34  void SetAngle(Real inAngle);
35 
36  // Test whether P is in the sector.
37  bool Contains(Vector2<Real> const& p) const;
38 
39  // The cosine and sine of the angle are used in queries, so all o
40  // angle, cos(angle), and sin(angle) are stored. If you set 'angle'
41  // via the public members, you must set all to be consistent. You
42  // can also call SetAngle(...) to ensure consistency.
44  Real radius;
47 
48 public:
49  // Comparisons to support sorted containers.
50  bool operator==(Sector2 const& sector) const;
51  bool operator!=(Sector2 const& sector) const;
52  bool operator< (Sector2 const& sector) const;
53  bool operator<=(Sector2 const& sector) const;
54  bool operator> (Sector2 const& sector) const;
55  bool operator>=(Sector2 const& sector) const;
56 };
57 
58 
59 template <typename Real>
61  :
62  vertex(Vector2<Real>::Zero()),
63  radius((Real)1),
64  direction(Vector2<Real>::Unit(0)),
65  angle((Real)GTE_C_PI),
66  cosAngle((Real)-1),
67  sinAngle((Real)0)
68 {
69 }
70 
71 template <typename Real>
72 Sector2<Real>::Sector2(Vector2<Real> const& inCenter, Real inRadius,
73  Vector2<Real> const& inDirection, Real inAngle)
74  :
75  vertex(inCenter),
76  radius(inRadius),
77  direction(inDirection)
78 {
79  SetAngle(inAngle);
80 }
81 
82 template <typename Real>
83 void Sector2<Real>::SetAngle(Real inAngle)
84 {
85  angle = inAngle;
86  cosAngle = cos(angle);
87  sinAngle = sin(angle);
88 }
89 
90 template <typename Real>
92 {
93  Vector2<Real> diff = p - vertex;
94  Real length = Length(diff);
96 }
97 
98 template <typename Real>
99 bool Sector2<Real>::operator==(Sector2 const& sector) const
100 {
101  return vertex == sector.vertex && radius == sector.radius
102  && direction == sector.direction && angle == sector.angle;
103 }
104 
105 template <typename Real>
106 bool Sector2<Real>::operator!=(Sector2 const& sector) const
107 {
108  return !operator==(sector);
109 }
110 
111 template <typename Real>
112 bool Sector2<Real>::operator<(Sector2 const& sector) const
113 {
114  if (vertex < sector.vertex)
115  {
116  return true;
117  }
118 
119  if (vertex > sector.vertex)
120  {
121  return false;
122  }
123 
124  if (radius < sector.radius)
125  {
126  return true;
127  }
128 
129  if (radius > sector.radius)
130  {
131  return false;
132  }
133 
134  if (direction < sector.direction)
135  {
136  return true;
137  }
138 
139  if (direction > sector.direction)
140  {
141  return false;
142  }
143 
144  return angle < sector.angle;
145 }
146 
147 template <typename Real>
148 bool Sector2<Real>::operator<=(Sector2 const& sector) const
149 {
150  return operator<(sector) || operator==(sector);
151 }
152 
153 template <typename Real>
154 bool Sector2<Real>::operator>(Sector2 const& sector) const
155 {
156  return !operator<=(sector);
157 }
158 
159 template <typename Real>
160 bool Sector2<Real>::operator>=(Sector2 const& sector) const
161 {
162  return !operator<(sector);
163 }
164 
165 }
bool operator<(Sector2 const &sector) const
Definition: GteSector2.h:112
Real cosAngle
Definition: GteSector2.h:46
GLfloat angle
Definition: glext.h:6466
Vector2< Real > vertex
Definition: GteSector2.h:43
bool operator>(Sector2 const &sector) const
Definition: GteSector2.h:154
bool Contains(Vector2< Real > const &p) const
Definition: GteSector2.h:91
#define GTE_C_PI
Definition: GteConstants.h:17
bool operator>=(Sector2 const &sector) const
Definition: GteSector2.h:160
Vector2< Real > direction
Definition: GteSector2.h:45
bool operator==(Sector2 const &sector) const
Definition: GteSector2.h:99
bool operator!=(Sector2 const &sector) const
Definition: GteSector2.h:106
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:790
DualQuaternion< Real > Length(DualQuaternion< Real > const &d, bool robust=false)
void SetAngle(Real inAngle)
Definition: GteSector2.h:83
Real sinAngle
Definition: GteSector2.h:46
GLfloat GLfloat p
Definition: glext.h:11668
bool operator<=(Sector2 const &sector) const
Definition: GteSector2.h:148


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01