GteHyperplane.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.1 (2016/07/28)
7 
8 #pragma once
9 
10 #include <Mathematics/GteMatrix.h>
12 
13 // The plane is represented as Dot(U,X) = c where U is a unit-length normal
14 // vector, c is the plane constant, and X is any point on the plane. The user
15 // must ensure that the normal vector is unit length.
16 
17 namespace gte
18 {
19 
20 template <int N, typename Real>
22 {
23 public:
24  // Construction and destruction. The default constructor sets the normal
25  // to (0,...,0,1) and the constant to zero (plane z = 0).
26  Hyperplane();
27 
28  // Specify U and c directly.
29  Hyperplane(Vector<N, Real> const& inNormal, Real inConstant);
30 
31  // U is specified, c = Dot(U,p) where p is a point on the hyperplane.
32  Hyperplane(Vector<N, Real> const& inNormal, Vector<N, Real> const& p);
33 
34  // U is a unit-length vector in the orthogonal complement of the set
35  // {p[1]-p[0],...,p[n-1]-p[0]} and c = Dot(U,p[0]), where the p[i] are
36  // pointson the hyperplane.
38 
39  // Public member access.
41  Real constant;
42 
43 public:
44  // Comparisons to support sorted containers.
45  bool operator==(Hyperplane const& hyperplane) const;
46  bool operator!=(Hyperplane const& hyperplane) const;
47  bool operator< (Hyperplane const& hyperplane) const;
48  bool operator<=(Hyperplane const& hyperplane) const;
49  bool operator> (Hyperplane const& hyperplane) const;
50  bool operator>=(Hyperplane const& hyperplane) const;
51 };
52 
53 // Template alias for convenience.
54 template <typename Real>
56 
57 
58 template <int N, typename Real>
60  :
61  constant((Real)0)
62 {
63  normal.MakeUnit(N - 1);
64 }
65 
66 template <int N, typename Real>
68  Real inConstant)
69  :
70  normal(inNormal),
71  constant(inConstant)
72 {
73 }
74 
75 template <int N, typename Real>
77  Vector<N, Real> const& p)
78  :
79  normal(inNormal),
80  constant(Dot(inNormal, p))
81 {
82 }
83 
84 template <int N, typename Real>
86 {
87  Matrix<N, N - 1, Real> edge;
88  for (int i = 0; i < N - 1; ++i)
89  {
90  edge.SetCol(i, p[i + 1] - p[0]);
91  }
92 
93  // Compute the 1-dimensional orthogonal complement of the edges of the
94  // simplex formed by the points p[].
95  SingularValueDecomposition<Real> svd(N, N - 1, 32);
96  svd.Solve(&edge[0], -1);
97  svd.GetUColumn(N - 1, &normal[0]);
98 
99  constant = Dot(normal, p[0]);
100 }
101 
102 template <int N, typename Real>
103 bool Hyperplane<N, Real>::operator==(Hyperplane const& hyperplane) const
104 {
105  return normal == hyperplane.normal && constant == hyperplane.constant;
106 }
107 
108 template <int N, typename Real>
109 bool Hyperplane<N, Real>::operator!=(Hyperplane const& hyperplane) const
110 {
111  return !operator==(hyperplane);
112 }
113 
114 template <int N, typename Real>
115 bool Hyperplane<N, Real>::operator<(Hyperplane const& hyperplane) const
116 {
117  if (normal < hyperplane.normal)
118  {
119  return true;
120  }
121 
122  if (normal > hyperplane.normal)
123  {
124  return false;
125  }
126 
127  return constant < hyperplane.constant;
128 }
129 
130 template <int N, typename Real>
131 bool Hyperplane<N, Real>::operator<=(Hyperplane const& hyperplane) const
132 {
133  return operator<(hyperplane) || operator==(hyperplane);
134 }
135 
136 template <int N, typename Real>
137 bool Hyperplane<N, Real>::operator>(Hyperplane const& hyperplane) const
138 {
139  return !operator<=(hyperplane);
140 }
141 
142 template <int N, typename Real>
143 bool Hyperplane<N, Real>::operator>=(Hyperplane const& hyperplane) const
144 {
145  return !operator<(hyperplane);
146 }
147 
148 
149 }
bool operator>=(Hyperplane const &hyperplane) const
bool operator==(Hyperplane const &hyperplane) const
bool operator<(Hyperplane const &hyperplane) const
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
void SetCol(int c, Vector< NumRows, Real > const &vec)
Definition: GteMatrix.h:362
bool operator>(Hyperplane const &hyperplane) const
bool operator!=(Hyperplane const &hyperplane) const
GLenum array
Definition: glext.h:6669
bool operator<=(Hyperplane const &hyperplane) const
Vector< N, Real > normal
Definition: GteHyperplane.h:40
GLfloat GLfloat p
Definition: glext.h:11668
unsigned int Solve(Real const *input, int sortType)
void GetUColumn(int index, Real *uColumn) const


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