Ellipse3.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.2020.01.10
  7. #pragma once
  8. #include <Mathematics/Vector2.h>
  9. #include <Mathematics/Vector3.h>
  10. // The plane containing ellipse is Dot(N,X-C) = 0 where X is any point in the
  11. // plane, C is the ellipse center, and N is a unit-length normal to the plane.
  12. // Vectors A0, A1, and N form an orthonormal right-handed set. The ellipse in
  13. // the plane is parameterized by X = C + e0*cos(t)*A0 + e1*sin(t)*A1, where A0
  14. // is the major axis, A1 is the minor axis, and e0 and e1 are the extents
  15. // along those axes. The angle t is in [-pi,pi) and e0 >= e1 > 0.
  16. namespace WwiseGTE
  17. {
  18. template <typename Real>
  19. class Ellipse3
  20. {
  21. public:
  22. // Construction and destruction. The default constructor sets center
  23. // to (0,0,0), A0 to (1,0,0), A1 to (0,1,0), normal to (0,0,1), e0
  24. // to 1, and e1 to 1.
  25. Ellipse3()
  26. :
  27. center(Vector3<Real>::Zero()),
  28. normal(Vector3<Real>::Unit(2)),
  29. extent{ (Real)1, (Real)1 }
  30. {
  31. axis[0] = Vector3<Real>::Unit(0);
  32. axis[1] = Vector3<Real>::Unit(1);
  33. }
  34. Ellipse3(Vector3<Real> const& inCenter, Vector3<Real> const& inNormal,
  35. Vector3<Real> const inAxis[2], Vector2<Real> const& inExtent)
  36. :
  37. center(inCenter),
  38. normal(inNormal),
  39. extent(inExtent)
  40. {
  41. for (int i = 0; i < 2; ++i)
  42. {
  43. axis[i] = inAxis[i];
  44. }
  45. }
  46. // Public member access.
  47. Vector3<Real> center, normal;
  48. Vector3<Real> axis[2];
  49. Vector2<Real> extent;
  50. public:
  51. // Comparisons to support sorted containers.
  52. bool operator==(Ellipse3 const& ellipse) const
  53. {
  54. return center == ellipse.center
  55. && normal == ellipse.normal
  56. && axis[0] == ellipse.axis[0]
  57. && axis[1] == ellipse.axis[1]
  58. && extent == ellipse.extent;
  59. }
  60. bool operator!=(Ellipse3 const& ellipse) const
  61. {
  62. return !operator==(ellipse);
  63. }
  64. bool operator< (Ellipse3 const& ellipse) const
  65. {
  66. if (center < ellipse.center)
  67. {
  68. return true;
  69. }
  70. if (center > ellipse.center)
  71. {
  72. return false;
  73. }
  74. if (normal < ellipse.normal)
  75. {
  76. return true;
  77. }
  78. if (normal > ellipse.normal)
  79. {
  80. return false;
  81. }
  82. if (axis[0] < ellipse.axis[0])
  83. {
  84. return true;
  85. }
  86. if (axis[0] > ellipse.axis[0])
  87. {
  88. return false;
  89. }
  90. if (axis[1] < ellipse.axis[1])
  91. {
  92. return true;
  93. }
  94. if (axis[1] > ellipse.axis[1])
  95. {
  96. return false;
  97. }
  98. return extent < ellipse.extent;
  99. }
  100. bool operator<=(Ellipse3 const& ellipse) const
  101. {
  102. return !ellipse.operator<(*this);
  103. }
  104. bool operator> (Ellipse3 const& ellipse) const
  105. {
  106. return ellipse.operator<(*this);
  107. }
  108. bool operator>=(Ellipse3 const& ellipse) const
  109. {
  110. return !operator<(ellipse);
  111. }
  112. };
  113. }