GteCone.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/GteRay.h>
12 #include <limits>
13 
14 // An acute cone is Dot(A,X-V) = |X-V| cos(t) where V is the vertex, A is the
15 // unit-length direction of the axis of the cone, and T is the cone angle with
16 // 0 < t < pi/2. The cone interior is defined by the inequality
17 // Dot(A,X-V) >= |X-V| cos(t). Since cos(t) > 0, we can avoid computing
18 // square roots. The solid cone is defined by the inequality
19 // Dot(A,X-V)^2 >= Dot(X-V,X-V) cos(t)^2. This is an infinite, single-sided
20 // cone.
21 //
22 // The cone may be truncated by a plane perpendicular to its axis at a height
23 // h from the vertex (distance from the vertex to the intersection of the
24 // plane and the axis). The infinite cone has h = infinity. The finite cone
25 // has a disk of intersection between the plane and infinite cone. The radius
26 // r of the disk is r = h*tan(t).
27 
28 namespace gte
29 {
30 
31 template <int N, typename Real>
32 class Cone
33 {
34 public:
35  // Construction and destruction. The default constructor sets center to
36  // (0,...,0), axis to (0,...,0,1), cosAngle and sinAngle to 1/sqrt(2)
37  // [angle is pi/4], and height to 1.
38  Cone();
39 
40  // The axis direction must be unit-length and the angle must be in
41  // (0,pi/2). The height is set to std::numeric_limits<float>::max().
42  Cone(Ray<N, Real> const& inRay, Real inAngle);
43 
44  // The axis direction must be unit-length and the angle must be in
45  // (0,pi/2). The height must be positive.
46  // std::numeric_limits<float>::max().
47  Cone(Ray<N, Real> const& inRay, Real inAngle, Real inHeight);
48 
49  // The angle must be in (0,pi/2). The function sets 'angle' and computes
50  // 'cosAngle' and 'sinAngle'.
51  void SetAngle(Real inAngle);
52 
53  // The cone vertex is the ray origin and the cone axis direction is the
54  // ray direction. The direction must be unit length. The angle must be
55  // in (0,pi/2). The height must be in (0,+infinity), where +infinity is
56  // std::numeric_limits<Real>::max().
58  Real angle;
59  Real height;
60 
61  // Members derived from 'angle', to avoid calling trigonometric functions
62  // in geometric queries (for speed). You may set 'angle' and compute
63  // these by calling SetAngle(inAngle).
65 
66 public:
67  // Comparisons to support sorted containers. These based only on 'ray',
68  // 'angle', and 'height'.
69  bool operator==(Cone const& cone) const;
70  bool operator!=(Cone const& cone) const;
71  bool operator< (Cone const& cone) const;
72  bool operator<=(Cone const& cone) const;
73  bool operator> (Cone const& cone) const;
74  bool operator>=(Cone const& cone) const;
75 };
76 
77 // Template alias for convenience.
78 template <typename Real>
80 
81 
82 template <int N, typename Real>
84  :
85  angle((Real)GTE_C_QUARTER_PI),
86  height((Real)1),
87  cosAngle(angle),
88  sinAngle(angle),
90 {
91  ray.origin.MakeZero();
92  ray.direction.MakeUnit(N - 1);
93 }
94 
95 template <int N, typename Real>
96 Cone<N, Real>::Cone(Ray<N, Real> const& inRay, Real inAngle)
97  :
98  ray(inRay),
99  angle(inAngle),
100  height(std::numeric_limits<Real>::max()),
101  cosAngle(cos(angle)),
102  sinAngle(sin(angle)),
104 {
105 }
106 
107 template <int N, typename Real>
108 Cone<N, Real>::Cone(Ray<N, Real> const& inRay, Real inAngle, Real inHeight)
109  :
110  ray(inRay),
111  angle(inAngle),
112  height(inHeight),
113  cosAngle(cos(angle)),
114  sinAngle(sin(angle)),
116 {
117 }
118 
119 template <int N, typename Real>
120 void Cone<N, Real>::SetAngle(Real inAngle)
121 {
122  angle = inAngle;
123  cosAngle = cos(angle);
124  sinAngle = sin(angle);
126 }
127 
128 template <int N, typename Real>
129 bool Cone<N, Real>::operator==(Cone const& cone) const
130 {
131  return ray == cone.ray && angle == cone.angle && height == cone.height;
132 }
133 
134 template <int N, typename Real>
135 bool Cone<N, Real>::operator!=(Cone const& cone) const
136 {
137  return !operator==(cone);
138 }
139 
140 template <int N, typename Real>
141 bool Cone<N, Real>::operator<(Cone const& cone) const
142 {
143  if (ray < cone.ray)
144  {
145  return true;
146  }
147 
148  if (ray > cone.ray)
149  {
150  return false;
151  }
152 
153  if (angle < cone.angle)
154  {
155  return true;
156  }
157 
158  if (angle > cone.angle)
159  {
160  return false;
161  }
162 
163  return height < cone.height;
164 }
165 
166 template <int N, typename Real>
167 bool Cone<N, Real>::operator<=(Cone const& cone) const
168 {
169  return operator<(cone) || operator==(cone);
170 }
171 
172 template <int N, typename Real>
173 bool Cone<N, Real>::operator>(Cone const& cone) const
174 {
175  return !operator<=(cone);
176 }
177 
178 template <int N, typename Real>
179 bool Cone<N, Real>::operator>=(Cone const& cone) const
180 {
181  return !operator<(cone);
182 }
183 
184 
185 }
bool operator==(Cone const &cone) const
Definition: GteCone.h:129
Real sinAngle
Definition: GteCone.h:64
bool operator<(Cone const &cone) const
Definition: GteCone.h:141
Real height
Definition: GteCone.h:59
bool operator>(Cone const &cone) const
Definition: GteCone.h:173
GLfloat angle
Definition: glext.h:6466
#define GTE_C_QUARTER_PI
Definition: GteConstants.h:19
Ray< N, Real > ray
Definition: GteCone.h:57
bool operator!=(Cone const &cone) const
Definition: GteCone.h:135
bool operator>=(Cone const &cone) const
Definition: GteCone.h:179
Cone()
Definition: GteCone.h:83
GLint GLsizei GLsizei height
Definition: glcorearb.h:98
void SetAngle(Real inAngle)
Definition: GteCone.h:120
bool operator<=(Cone const &cone) const
Definition: GteCone.h:167
Real cosAngle
Definition: GteCone.h:64
Real cosAngleSqr
Definition: GteCone.h:64
Real angle
Definition: GteCone.h:58


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