IntrHalfspace3Sphere3.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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/Hypersphere.h>
  11. // Queries for intersection of objects with halfspaces. These are useful for
  12. // containment testing, object culling, and clipping.
  13. namespace WwiseGTE
  14. {
  15. template <typename Real>
  16. class TIQuery<Real, Halfspace3<Real>, Sphere3<Real>>
  17. {
  18. public:
  19. struct Result
  20. {
  21. bool intersect;
  22. };
  23. Result operator()(Halfspace3<Real> const& halfspace, Sphere3<Real> const& sphere)
  24. {
  25. Result result;
  26. // Project the sphere center onto the normal line. The plane of
  27. // the halfspace occurs at the origin (zero) of the normal line.
  28. Real center = Dot(halfspace.normal, sphere.center) - halfspace.constant;
  29. // The sphere and halfspace intersect when the projection interval
  30. // maximum is nonnegative.
  31. result.intersect = (center + sphere.radius >= (Real)0);
  32. return result;
  33. }
  34. };
  35. }