Circle3.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/Vector3.h>
  9. // The circle is the intersection of the sphere |X-C|^2 = r^2 and the
  10. // plane Dot(N,X-C) = 0, where C is the circle center, r is the radius,
  11. // and N is a unit-length plane normal.
  12. namespace WwiseGTE
  13. {
  14. template <typename Real>
  15. class Circle3
  16. {
  17. public:
  18. // Construction and destruction. The default constructor sets center
  19. // to (0,0,0), normal to (0,0,1), and radius to 1.
  20. Circle3()
  21. :
  22. center(Vector3<Real>::Zero()),
  23. normal(Vector3<Real>::Unit(2)),
  24. radius((Real)1)
  25. {
  26. }
  27. Circle3(Vector3<Real> const& inCenter, Vector3<Real> const& inNormal, Real inRadius)
  28. :
  29. center(inCenter),
  30. normal(inNormal),
  31. radius(inRadius)
  32. {
  33. }
  34. // Public member access.
  35. Vector3<Real> center, normal;
  36. Real radius;
  37. public:
  38. // Comparisons to support sorted containers.
  39. bool operator==(Circle3 const& circle) const
  40. {
  41. return center == circle.center
  42. && normal == circle.normal
  43. && radius == circle.radius;
  44. }
  45. bool operator!=(Circle3 const& circle) const
  46. {
  47. return !operator==(circle);
  48. }
  49. bool operator< (Circle3 const& circle) const
  50. {
  51. if (center < circle.center)
  52. {
  53. return true;
  54. }
  55. if (center > circle.center)
  56. {
  57. return false;
  58. }
  59. if (normal < circle.normal)
  60. {
  61. return true;
  62. }
  63. if (normal > circle.normal)
  64. {
  65. return false;
  66. }
  67. return radius < circle.radius;
  68. }
  69. bool operator<=(Circle3 const& circle) const
  70. {
  71. return !circle.operator<(*this);
  72. }
  73. bool operator> (Circle3 const& circle) const
  74. {
  75. return circle.operator<(*this);
  76. }
  77. bool operator>=(Circle3 const& circle) const
  78. {
  79. return !operator<(circle);
  80. }
  81. };
  82. }