GteHypersphere.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 hypersphere is represented as |X-C| = R where C is the center and R is
13 // the radius. The hypersphere is a circle for dimension 2 or a sphere for
14 // dimension 3.
15 
16 namespace gte
17 {
18 
19 template <int N, typename Real>
21 {
22 public:
23  // Construction and destruction. The default constructor sets the center
24  // to (0,...,0) and the radius to 1.
25  Hypersphere();
26  Hypersphere(Vector<N, Real> const& inCenter, Real inRadius);
27 
28  // Public member access.
30  Real radius;
31 
32 public:
33  // Comparisons to support sorted containers.
34  bool operator==(Hypersphere const& hypersphere) const;
35  bool operator!=(Hypersphere const& hypersphere) const;
36  bool operator< (Hypersphere const& hypersphere) const;
37  bool operator<=(Hypersphere const& hypersphere) const;
38  bool operator> (Hypersphere const& hypersphere) const;
39  bool operator>=(Hypersphere const& hypersphere) const;
40 };
41 
42 // Template aliases for convenience.
43 template <typename Real>
45 
46 template <typename Real>
48 
49 
50 template <int N, typename Real>
52  :
53  radius((Real)1)
54 {
55  center.MakeZero();
56 }
57 
58 template <int N, typename Real>
60  Real inRadius)
61  :
62  center(inCenter),
63  radius(inRadius)
64 {
65 }
66 
67 template <int N, typename Real>
68 bool Hypersphere<N, Real>::operator==(Hypersphere const& hypersphere) const
69 {
70  return center == hypersphere.center && radius == hypersphere.radius;
71 }
72 
73 template <int N, typename Real>
74 bool Hypersphere<N, Real>::operator!=(Hypersphere const& hypersphere) const
75 {
76  return !operator==(hypersphere);
77 }
78 
79 template <int N, typename Real>
80 bool Hypersphere<N, Real>::operator<(Hypersphere const& hypersphere) const
81 {
82  if (center < hypersphere.center)
83  {
84  return true;
85  }
86 
87  if (center > hypersphere.center)
88  {
89  return false;
90  }
91 
92  return radius < hypersphere.radius;
93 }
94 
95 template <int N, typename Real>
96 bool Hypersphere<N, Real>::operator<=(Hypersphere const& hypersphere) const
97 {
98  return operator<(hypersphere) || operator==(hypersphere);
99 }
100 
101 template <int N, typename Real>
102 bool Hypersphere<N, Real>::operator>(Hypersphere const& hypersphere) const
103 {
104  return !operator<=(hypersphere);
105 }
106 
107 template <int N, typename Real>
108 bool Hypersphere<N, Real>::operator>=(Hypersphere const& hypersphere) const
109 {
110  return !operator<(hypersphere);
111 }
112 
113 
114 }
bool operator==(Hypersphere const &hypersphere) const
bool operator>=(Hypersphere const &hypersphere) const
bool operator<(Hypersphere const &hypersphere) const
bool operator!=(Hypersphere const &hypersphere) const
bool operator>(Hypersphere const &hypersphere) const
Vector< N, Real > center
bool operator<=(Hypersphere const &hypersphere) const


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