EllipsoidGeodesic.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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/RiemannianGeodesic.h>
  9. namespace WwiseGTE
  10. {
  11. template <typename Real>
  12. class EllipsoidGeodesic : public RiemannianGeodesic<Real>
  13. {
  14. public:
  15. // The ellipsoid is (x/a)^2 + (y/b)^2 + (z/c)^2 = 1, where xExtent is
  16. // 'a', yExtent is 'b', and zExtent is 'c'. The surface is represented
  17. // parametrically by angles u and v, say
  18. // P(u,v) = (x(u,v),y(u,v),z(u,v)),
  19. // P(u,v) =(a*cos(u)*sin(v), b*sin(u)*sin(v), c*cos(v))
  20. // with 0 <= u < 2*pi and 0 <= v <= pi. The first-order derivatives
  21. // are
  22. // dP/du = (-a*sin(u)*sin(v), b*cos(u)*sin(v), 0)
  23. // dP/dv = (a*cos(u)*cos(v), b*sin(u)*cos(v), -c*sin(v))
  24. // The metric tensor elements are
  25. // g_{00} = Dot(dP/du,dP/du)
  26. // g_{01} = Dot(dP/du,dP/dv)
  27. // g_{10} = g_{01}
  28. // g_{11} = Dot(dP/dv,dP/dv)
  29. EllipsoidGeodesic(Real xExtent, Real yExtent, Real zExtent)
  30. :
  31. RiemannianGeodesic<Real>(2),
  32. mXExtent(xExtent),
  33. mYExtent(yExtent),
  34. mZExtent(zExtent)
  35. {
  36. }
  37. virtual ~EllipsoidGeodesic()
  38. {
  39. }
  40. Vector3<Real> ComputePosition(GVector<Real> const& point)
  41. {
  42. Real cos0 = std::cos(point[0]);
  43. Real sin0 = std::sin(point[0]);
  44. Real cos1 = std::cos(point[1]);
  45. Real sin1 = std::sin(point[1]);
  46. return Vector3<Real>
  47. {
  48. mXExtent * cos0 * sin1,
  49. mYExtent * sin0 * sin1,
  50. mZExtent * cos1
  51. };
  52. }
  53. // To compute the geodesic path connecting two parameter points
  54. // (u0,v0) and (u1,v1):
  55. //
  56. // float a, b, c; // the extents of the ellipsoid
  57. // EllipsoidGeodesic<float> EG(a,b,c);
  58. // GVector<float> param0(2), param1(2);
  59. // param0[0] = u0;
  60. // param0[1] = v0;
  61. // param1[0] = u1;
  62. // param1[1] = v1;
  63. //
  64. // int quantity;
  65. // std:vector<GVector<float>> path;
  66. // EG.ComputeGeodesic(param0, param1, quantity, path);
  67. private:
  68. virtual void ComputeMetric(GVector<Real> const& point) override
  69. {
  70. mCos0 = std::cos(point[0]);
  71. mSin0 = std::sin(point[0]);
  72. mCos1 = std::cos(point[1]);
  73. mSin1 = std::sin(point[1]);
  74. mDer0 = { -mXExtent * mSin0 * mSin1, mYExtent * mCos0 * mSin1, (Real)0 };
  75. mDer1 = { mXExtent * mCos0 * mCos1, mYExtent * mSin0 * mCos1, -mZExtent * mSin1 };
  76. this->mMetric(0, 0) = Dot(mDer0, mDer0);
  77. this->mMetric(0, 1) = Dot(mDer0, mDer1);
  78. this->mMetric(1, 0) = this->mMetric(0, 1);
  79. this->mMetric(1, 1) = Dot(mDer1, mDer1);
  80. }
  81. virtual void ComputeChristoffel1(GVector<Real> const&) override
  82. {
  83. Vector3<Real> der00
  84. {
  85. -mXExtent * mCos0 * mSin1,
  86. -mYExtent * mSin0 * mSin1,
  87. (Real)0
  88. };
  89. Vector3<Real> der01
  90. {
  91. -mXExtent * mSin0 * mCos1,
  92. mYExtent * mCos0 * mCos1,
  93. (Real)0
  94. };
  95. Vector3<Real> der11
  96. {
  97. -mXExtent * mCos0 * mSin1,
  98. -mYExtent * mSin0 * mSin1,
  99. -mZExtent * mCos1
  100. };
  101. this->mChristoffel1[0](0, 0) = Dot(der00, mDer0);
  102. this->mChristoffel1[0](0, 1) = Dot(der01, mDer0);
  103. this->mChristoffel1[0](1, 0) = this->mChristoffel1[0](0, 1);
  104. this->mChristoffel1[0](1, 1) = Dot(der11, mDer0);
  105. this->mChristoffel1[1](0, 0) = Dot(der00, mDer1);
  106. this->mChristoffel1[1](0, 1) = Dot(der01, mDer1);
  107. this->mChristoffel1[1](1, 0) = this->mChristoffel1[1](0, 1);
  108. this->mChristoffel1[1](1, 1) = Dot(der11, mDer1);
  109. }
  110. // The ellipsoid axis half-lengths.
  111. Real mXExtent, mYExtent, mZExtent;
  112. // We are guaranteed that RiemannianGeodesic calls ComputeMetric
  113. // before ComputeChristoffel1. Thus, we can compute the surface
  114. // first- and second-order derivatives in ComputeMetric and cache
  115. // the results for use in ComputeChristoffel1.
  116. Real mCos0, mSin0, mCos1, mSin1;
  117. Vector3<Real> mDer0, mDer1;
  118. };
  119. }