Sphere.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // This code is in the public domain -- Ignacio Castaño <castano@gmail.com>
  2. #pragma once
  3. #ifndef NV_MATH_SPHERE_H
  4. #define NV_MATH_SPHERE_H
  5. #include "Vector.h"
  6. namespace nv
  7. {
  8. class Sphere
  9. {
  10. public:
  11. Sphere() {}
  12. Sphere(Vector3::Arg center, float radius) : center(center), radius(radius) {}
  13. Sphere(Vector3::Arg center) : center(center), radius(0.0f) {}
  14. Sphere(Vector3::Arg p0, Vector3::Arg p1);
  15. Sphere(Vector3::Arg p0, Vector3::Arg p1, Vector3::Arg p2);
  16. Sphere(Vector3::Arg p0, Vector3::Arg p1, Vector3::Arg p2, Vector3::Arg p3);
  17. Vector3 center;
  18. float radius;
  19. };
  20. // Returns negative values if point is inside.
  21. float distanceSquared(const Sphere & sphere, const Vector3 &point);
  22. // Welz's algorithm. Fairly slow, recursive implementation uses large stack.
  23. Sphere miniBall(const Vector3 * pointArray, uint pointCount);
  24. Sphere approximateSphere_Ritter(const Vector3 * pointArray, uint pointCount);
  25. Sphere approximateSphere_AABB(const Vector3 * pointArray, uint pointCount);
  26. Sphere approximateSphere_EPOS6(const Vector3 * pointArray, uint pointCount);
  27. Sphere approximateSphere_EPOS14(const Vector3 * pointArray, uint pointCount);
  28. } // nv namespace
  29. #endif // NV_MATH_SPHERE_H