GteHalfspace.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/GteVector.h>
11 
12 // The halfspace is represented as Dot(N,X) >= c where N is a unit-length
13 // normal vector, c is the plane constant, and X is any point in space.
14 // The user must ensure that the normal vector is unit length.
15 
16 namespace gte
17 {
18 
19 template <int N, typename Real>
20 class Halfspace
21 {
22 public:
23  // Construction and destruction. The default constructor sets the normal
24  // to (0,...,0,1) and the constant to zero (halfspace x[N-1] >= 0).
25  Halfspace();
26 
27  // Specify N and c directly.
28  Halfspace(Vector<N, Real> const& inNormal, Real inConstant);
29 
30  // Public member access.
32  Real constant;
33 
34 public:
35  // Comparisons to support sorted containers.
36  bool operator==(Halfspace const& halfspace) const;
37  bool operator!=(Halfspace const& halfspace) const;
38  bool operator< (Halfspace const& halfspace) const;
39  bool operator<=(Halfspace const& halfspace) const;
40  bool operator> (Halfspace const& halfspace) const;
41  bool operator>=(Halfspace const& halfspace) const;
42 };
43 
44 // Template alias for convenience.
45 template <typename Real>
47 
48 
49 template <int N, typename Real>
51  :
52  constant((Real)0)
53 {
54  normal.MakeUnit(N - 1);
55 }
56 
57 template <int N, typename Real>
59  Real inConstant)
60  :
61  normal(inNormal),
62  constant(inConstant)
63 {
64 }
65 
66 template <int N, typename Real>
67 bool Halfspace<N, Real>::operator==(Halfspace const& halfspace) const
68 {
69  return normal == halfspace.normal && constant == halfspace.constant;
70 }
71 
72 template <int N, typename Real>
73 bool Halfspace<N, Real>::operator!=(Halfspace const& halfspace) const
74 {
75  return !operator==(halfspace);
76 }
77 
78 template <int N, typename Real>
79 bool Halfspace<N, Real>::operator<(Halfspace const& halfspace) const
80 {
81  if (normal < halfspace.normal)
82  {
83  return true;
84  }
85 
86  if (normal > halfspace.normal)
87  {
88  return false;
89  }
90 
91  return constant < halfspace.constant;
92 }
93 
94 template <int N, typename Real>
95 bool Halfspace<N, Real>::operator<=(Halfspace const& halfspace) const
96 {
97  return operator<(halfspace) || operator==(halfspace);
98 }
99 
100 template <int N, typename Real>
101 bool Halfspace<N, Real>::operator>(Halfspace const& halfspace) const
102 {
103  return !operator<=(halfspace);
104 }
105 
106 template <int N, typename Real>
107 bool Halfspace<N, Real>::operator>=(Halfspace const& halfspace) const
108 {
109  return !operator<(halfspace);
110 }
111 
112 
113 }
bool operator==(Halfspace const &halfspace) const
Definition: GteHalfspace.h:67
bool operator>=(Halfspace const &halfspace) const
Definition: GteHalfspace.h:107
bool operator<=(Halfspace const &halfspace) const
Definition: GteHalfspace.h:95
bool operator>(Halfspace const &halfspace) const
Definition: GteHalfspace.h:101
Vector< N, Real > normal
Definition: GteHalfspace.h:31
bool operator<(Halfspace const &halfspace) const
Definition: GteHalfspace.h:79
bool operator!=(Halfspace const &halfspace) const
Definition: GteHalfspace.h:73


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