Projection.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/Hyperellipsoid.h>
  9. #include <Mathematics/Line.h>
  10. namespace WwiseGTE
  11. {
  12. // Project an ellipse onto a line. The projection interval is
  13. // [smin,smax] and corresponds to the line segment P+s*D, where
  14. // smin <= s <= smax.
  15. template <typename Real>
  16. void Project(Ellipse2<Real> const& ellipse, Line2<Real> const& line,
  17. Real& smin, Real& smax)
  18. {
  19. // Center of projection interval.
  20. Real center = Dot(line.direction, ellipse.center - line.origin);
  21. // Radius of projection interval.
  22. Real tmp[2] =
  23. {
  24. ellipse.extent[0] * Dot(line.direction, ellipse.axis[0]),
  25. ellipse.extent[1] * Dot(line.direction, ellipse.axis[1])
  26. };
  27. Real rSqr = tmp[0] * tmp[0] + tmp[1] * tmp[1];
  28. Real radius = std::sqrt(rSqr);
  29. smin = center - radius;
  30. smax = center + radius;
  31. }
  32. // Project an ellipsoid onto a line. The projection interval is
  33. // [smin,smax] and corresponds to the line segment P+s*D, where
  34. // smin <= s <= smax.
  35. template <typename Real>
  36. void Project(Ellipsoid3<Real> const& ellipsoid,
  37. Line3<Real> const& line, Real& smin, Real& smax)
  38. {
  39. // Center of projection interval.
  40. Real center = Dot(line.direction, ellipsoid.center - line.origin);
  41. // Radius of projection interval.
  42. Real tmp[3] =
  43. {
  44. ellipsoid.extent[0] * Dot(line.direction, ellipsoid.axis[0]),
  45. ellipsoid.extent[1] * Dot(line.direction, ellipsoid.axis[1]),
  46. ellipsoid.extent[2] * Dot(line.direction, ellipsoid.axis[2])
  47. };
  48. Real rSqr = tmp[0] * tmp[0] + tmp[1] * tmp[1] + tmp[2] * tmp[2];
  49. Real radius = std::sqrt(rSqr);
  50. smin = center - radius;
  51. smax = center + radius;
  52. }
  53. }