IntrHalfspace3Ellipsoid3.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/TIQuery.h>
  9. #include <Mathematics/Halfspace.h>
  10. #include <Mathematics/Hyperellipsoid.h>
  11. #include <Mathematics/Matrix3x3.h>
  12. // Queries for intersection of objects with halfspaces. These are useful for
  13. // containment testing, object culling, and clipping.
  14. namespace WwiseGTE
  15. {
  16. template <typename Real>
  17. class TIQuery<Real, Halfspace3<Real>, Ellipsoid3<Real>>
  18. {
  19. public:
  20. struct Result
  21. {
  22. bool intersect;
  23. };
  24. Result operator()(Halfspace3<Real> const& halfspace, Ellipsoid3<Real> const& ellipsoid)
  25. {
  26. // Project the ellipsoid onto the normal line. The plane of the
  27. // halfspace occurs at the origin (zero) of the normal line.
  28. Result result;
  29. Matrix3x3<Real> MInverse;
  30. ellipsoid.GetMInverse(MInverse);
  31. Real discr = Dot(halfspace.normal, MInverse * halfspace.normal);
  32. Real extent = std::sqrt(std::max(discr, (Real)0));
  33. Real center = Dot(halfspace.normal, ellipsoid.center) - halfspace.constant;
  34. Real tmax = center + extent;
  35. // The ellipsoid and halfspace intersect when the projection
  36. // interval maximum is nonnegative.
  37. result.intersect = (tmax >= (Real)0);
  38. return result;
  39. }
  40. };
  41. }