Hypersphere.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // David Eberly, Geometric Tools, Redmond WA 98052
  2. // Copyright (c) 1998-2020
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
  6. // Version: 4.0.2019.08.13
  7. #pragma once
  8. #include <Mathematics/Vector.h>
  9. // The hypersphere is represented as |X-C| = R where C is the center and R is
  10. // the radius. The hypersphere is a circle for dimension 2 or a sphere for
  11. // dimension 3.
  12. namespace WwiseGTE
  13. {
  14. template <int N, typename Real>
  15. class Hypersphere
  16. {
  17. public:
  18. // Construction and destruction. The default constructor sets the center
  19. // to (0,...,0) and the radius to 1.
  20. Hypersphere()
  21. :
  22. radius((Real)1)
  23. {
  24. center.MakeZero();
  25. }
  26. Hypersphere(Vector<N, Real> const& inCenter, Real inRadius)
  27. :
  28. center(inCenter),
  29. radius(inRadius)
  30. {
  31. }
  32. // Public member access.
  33. Vector<N, Real> center;
  34. Real radius;
  35. public:
  36. // Comparisons to support sorted containers.
  37. bool operator==(Hypersphere const& hypersphere) const
  38. {
  39. return center == hypersphere.center && radius == hypersphere.radius;
  40. }
  41. bool operator!=(Hypersphere const& hypersphere) const
  42. {
  43. return !operator==(hypersphere);
  44. }
  45. bool operator< (Hypersphere const& hypersphere) const
  46. {
  47. if (center < hypersphere.center)
  48. {
  49. return true;
  50. }
  51. if (center > hypersphere.center)
  52. {
  53. return false;
  54. }
  55. return radius < hypersphere.radius;
  56. }
  57. bool operator<=(Hypersphere const& hypersphere) const
  58. {
  59. return !hypersphere.operator<(*this);
  60. }
  61. bool operator> (Hypersphere const& hypersphere) const
  62. {
  63. return hypersphere.operator<(*this);
  64. }
  65. bool operator>=(Hypersphere const& hypersphere) const
  66. {
  67. return !operator<(hypersphere);
  68. }
  69. };
  70. // Template aliases for convenience.
  71. template <typename Real>
  72. using Circle2 = Hypersphere<2, Real>;
  73. template <typename Real>
  74. using Sphere3 = Hypersphere<3, Real>;
  75. }