GteTetrahedron3.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/GteVector3.h>
12 
13 // The tetrahedron is represented as an array of four vertices: V0, V1, V2,
14 // and V3. The vertices are ordered so that the triangular faces are
15 // counterclockwise-ordered triangles when viewed by an observer outside the
16 // tetrahedron:
17 // face 0 = <V[0],V[2],V[1]>
18 // face 1 = <V[0],V[1],V[3]>
19 // face 2 = <V[0],V[3],V[2]>
20 // face 3 = <V[1],V[2],V[3]>
21 
22 namespace gte
23 {
24 
25 template <typename Real>
27 {
28 public:
29  // Construction and destruction. The default constructor sets the
30  // vertices to (0,0,0), (1,0,0), (0,1,0), and (0,0,1).
31  Tetrahedron3();
33  Vector3<Real> const& v2, Vector3<Real> const& v3);
34  Tetrahedron3(Vector3<Real> const inV[4]);
35 
36  // Get the vertex indices for the specified face. The input 'face' must
37  // be in {0,1,2,3}.
38  void GetFaceIndices(int face, int index[3]) const;
39 
40  // Construct the planes of the faces. The planes have outer pointing
41  // normal vectors. The plane indexing is the same as the face indexing
42  // mentioned previously.
43  void GetPlanes(Plane3<Real> plane[4]) const;
44 
45  // Public member access.
47 
48 public:
49  // Comparisons to support sorted containers.
50  bool operator==(Tetrahedron3 const& tetrahedron) const;
51  bool operator!=(Tetrahedron3 const& tetrahedron) const;
52  bool operator< (Tetrahedron3 const& tetrahedron) const;
53  bool operator<=(Tetrahedron3 const& tetrahedron) const;
54  bool operator> (Tetrahedron3 const& tetrahedron) const;
55  bool operator>=(Tetrahedron3 const& tetrahedron) const;
56 };
57 
58 
59 template <typename Real>
61 {
62  v[0] = Vector3<Real>::Zero();
63  v[1] = Vector3<Real>::Unit(0);
64  v[2] = Vector3<Real>::Unit(1);
65  v[3] = Vector3<Real>::Unit(2);
66 }
67 
68 template <typename Real>
70  Vector3<Real> const& v1, Vector3<Real> const& v2, Vector3<Real> const& v3)
71 {
72  v[0] = v0;
73  v[1] = v1;
74  v[2] = v2;
75  v[3] = v3;
76 }
77 
78 template <typename Real>
80 {
81  for (int i = 0; i < 4; ++i)
82  {
83  v[i] = inV[i];
84  }
85 }
86 
87 template <typename Real>
89 const
90 {
91  if (face == 0)
92  {
93  index[0] = 0;
94  index[1] = 2;
95  index[2] = 1;
96  }
97  else if (face == 1)
98  {
99  index[0] = 0;
100  index[1] = 1;
101  index[2] = 3;
102  }
103  else if (face == 2)
104  {
105  index[0] = 0;
106  index[1] = 3;
107  index[2] = 2;
108  }
109  else // face == 3 (no index validation is performed)
110  {
111  index[0] = 1;
112  index[1] = 2;
113  index[2] = 3;
114  }
115 }
116 
117 template <typename Real>
119 {
120  Vector3<Real> edge10 = v[1] - v[0];
121  Vector3<Real> edge20 = v[2] - v[0];
122  Vector3<Real> edge30 = v[3] - v[0];
123  Vector3<Real> edge21 = v[2] - v[1];
124  Vector3<Real> edge31 = v[3] - v[1];
125 
126  plane[0].normal = UnitCross(edge20, edge10); // <v0,v2,v1>
127  plane[1].normal = UnitCross(edge10, edge30); // <v0,v1,v3>
128  plane[2].normal = UnitCross(edge30, edge20); // <v0,v3,v2>
129  plane[3].normal = UnitCross(edge21, edge31); // <v1,v2,v3>
130 
131  Real det = Dot(edge10, plane[3].normal);
132  if (det < (Real)0)
133  {
134  // The normals are inner pointing, reverse their directions.
135  for (int i = 0; i < 4; ++i)
136  {
137  plane[i].normal = -plane[i].normal;
138  }
139  }
140 
141  for (int i = 0; i < 4; ++i)
142  {
143  plane[i].constant = Dot(v[i], plane[i].normal);
144  }
145 }
146 
147 template <typename Real>
148 bool Tetrahedron3<Real>::operator==(Tetrahedron3 const& tetrahedron) const
149 {
150  return v[0] == tetrahedron.v[0]
151  && v[1] == tetrahedron.v[1]
152  && v[2] == tetrahedron.v[2]
153  && v[3] == tetrahedron.v[3];
154 }
155 
156 template <typename Real>
157 bool Tetrahedron3<Real>::operator!=(Tetrahedron3 const& tetrahedron) const
158 {
159  return !operator==(tetrahedron);
160 }
161 
162 template <typename Real>
163 bool Tetrahedron3<Real>::operator<(Tetrahedron3 const& tetrahedron) const
164 {
165  for (int i = 0; i < 4; ++i)
166  {
167  if (v[i] < tetrahedron.v[i])
168  {
169  return true;
170  }
171 
172  if (v[i] > tetrahedron.v[i])
173  {
174  return false;
175  }
176  }
177 
178  return false;
179 }
180 
181 template <typename Real>
182 bool Tetrahedron3<Real>::operator<=(Tetrahedron3 const& tetrahedron) const
183 {
184  return operator<(tetrahedron) || operator==(tetrahedron);
185 }
186 
187 template <typename Real>
188 bool Tetrahedron3<Real>::operator>(Tetrahedron3 const& tetrahedron) const
189 {
190  return !operator<=(tetrahedron);
191 }
192 
193 template <typename Real>
194 bool Tetrahedron3<Real>::operator>=(Tetrahedron3 const& tetrahedron) const
195 {
196  return !operator<(tetrahedron);
197 }
198 
199 
200 }
GLfloat GLfloat v1
Definition: glcorearb.h:812
Vector3< Real > v[4]
Vector< N, Real > UnitCross(Vector< N, Real > const &v0, Vector< N, Real > const &v1, bool robust=false)
Definition: GteVector3.h:130
bool operator<(Tetrahedron3 const &tetrahedron) const
void GetFaceIndices(int face, int index[3]) const
static Vector Zero()
Definition: GteVector.h:295
bool operator>=(Tetrahedron3 const &tetrahedron) const
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLfloat GLfloat GLfloat GLfloat v3
Definition: glcorearb.h:814
GLfloat v0
Definition: glcorearb.h:811
bool operator>(Tetrahedron3 const &tetrahedron) const
const GLdouble * v
Definition: glcorearb.h:832
bool operator<=(Tetrahedron3 const &tetrahedron) const
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:813
GLuint index
Definition: glcorearb.h:781
bool operator==(Tetrahedron3 const &tetrahedron) const
Vector< N, Real > normal
Definition: GteHyperplane.h:40
void GetPlanes(Plane3< Real > plane[4]) const
GLenum GLuint GLint GLenum face
Definition: glext.h:3311
static Vector Unit(int d)
Definition: GteVector.h:303
bool operator!=(Tetrahedron3 const &tetrahedron) const


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