GteEllipse3.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 #include <Mathematics/GteVector3.h>
12 
13 // The plane containing ellipse is Dot(N,X-C) = 0 where X is any point in the
14 // plane, C is the ellipse center, and N is a unit-length normal to the plane.
15 // Vectors A0, A1, and N form an orthonormal right-handed set. The ellipse in
16 // the plane is parameterized by X = C + e0*cos(t)*A0 + e1*sin(t)*A1, where A0
17 // is the major axis, A1 is the minor axis, and e0 and e1 are the extents
18 // along those axes. The angle t is in [-pi,pi) and e0 >= e1 > 0.
19 
20 namespace gte
21 {
22 
23 template <typename Real>
24 class Ellipse3
25 {
26 public:
27  // Construction and destruction. The default constructor sets center to
28  // (0,0,0), A0 to (1,0,0), A1 to (0,1,0), normal to (0,0,1), e0 to 1, and
29  // e1 to 1.
30  Ellipse3();
31  Ellipse3(Vector3<Real> const& inCenter, Vector3<Real> const& inNormal,
32  Vector3<Real> const inAxis[2], Vector2<Real> const& inExtent);
33 
34  // Public member access.
38 
39 public:
40  // Comparisons to support sorted containers.
41  bool operator==(Ellipse3 const& ellipse) const;
42  bool operator!=(Ellipse3 const& ellipse) const;
43  bool operator< (Ellipse3 const& ellipse) const;
44  bool operator<=(Ellipse3 const& ellipse) const;
45  bool operator> (Ellipse3 const& ellipse) const;
46  bool operator>=(Ellipse3 const& ellipse) const;
47 };
48 
49 
50 template <typename Real>
52  :
53  center(Vector3<Real>::Zero()),
54  normal(Vector3<Real>::Unit(2)),
55  extent({ (Real)1, (Real)1 })
56 {
57  axis[0] = Vector3<Real>::Unit(0);
58  axis[1] = Vector3<Real>::Unit(1);
59 }
60 
61 template <typename Real>
63  Vector3<Real> const& inNormal, Vector3<Real> const inAxis[2],
64  Vector2<Real> const& inExtent)
65  :
66  center(inCenter),
67  normal(inNormal),
68  extent(inExtent)
69 {
70  for (int i = 0; i < 2; ++i)
71  {
72  axis[i] = inAxis[i];
73  }
74 }
75 
76 template <typename Real>
77 bool Ellipse3<Real>::operator==(Ellipse3 const& ellipse) const
78 {
79  return center == ellipse.center
80  && normal == ellipse.normal
81  && axis[0] == ellipse.axis[0]
82  && axis[1] == ellipse.axis[1]
83  && extent == ellipse.extent;
84 }
85 
86 template <typename Real>
87 bool Ellipse3<Real>::operator!=(Ellipse3 const& ellipse) const
88 {
89  return !operator==(ellipse);
90 }
91 
92 template <typename Real>
93 bool Ellipse3<Real>::operator<(Ellipse3 const& ellipse) const
94 {
95  if (center < ellipse.center)
96  {
97  return true;
98  }
99 
100  if (center > ellipse.center)
101  {
102  return false;
103  }
104 
105  if (normal < ellipse.normal)
106  {
107  return true;
108  }
109 
110  if (normal > ellipse.normal)
111  {
112  return false;
113  }
114 
115  if (axis[0] < ellipse.axis[0])
116  {
117  return true;
118  }
119 
120  if (axis[0] > ellipse.axis[0])
121  {
122  return false;
123  }
124 
125  if (axis[1] < ellipse.axis[1])
126  {
127  return true;
128  }
129 
130  if (axis[1] > ellipse.axis[1])
131  {
132  return false;
133  }
134 
135  return extent < ellipse.extent;
136 }
137 
138 template <typename Real>
139 bool Ellipse3<Real>::operator<=(Ellipse3 const& ellipse) const
140 {
141  return operator<(ellipse) || operator==(ellipse);
142 }
143 
144 template <typename Real>
145 bool Ellipse3<Real>::operator>(Ellipse3 const& ellipse) const
146 {
147  return !operator<=(ellipse);
148 }
149 
150 template <typename Real>
151 bool Ellipse3<Real>::operator>=(Ellipse3 const& ellipse) const
152 {
153  return !operator<(ellipse);
154 }
155 
156 
157 }
Vector3< Real > center
Definition: GteEllipse3.h:35
Vector3< Real > axis[2]
Definition: GteEllipse3.h:36
bool operator<(Ellipse3 const &ellipse) const
Definition: GteEllipse3.h:93
bool operator>(Ellipse3 const &ellipse) const
Definition: GteEllipse3.h:145
bool operator>=(Ellipse3 const &ellipse) const
Definition: GteEllipse3.h:151
bool operator<=(Ellipse3 const &ellipse) const
Definition: GteEllipse3.h:139
Vector3< Real > normal
Definition: GteEllipse3.h:35
bool operator!=(Ellipse3 const &ellipse) const
Definition: GteEllipse3.h:87
bool operator==(Ellipse3 const &ellipse) const
Definition: GteEllipse3.h:77
Vector2< Real > extent
Definition: GteEllipse3.h:37
static Vector Unit(int d)
Definition: GteVector.h:303


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