KrisLibrary  1.0.0
Sphere3D.h
1 #ifndef MATH3D_SPHERE3D_H
2 #define MATH3D_SPHERE3D_H
3 
4 #include "Point.h"
5 
6 namespace Math3D {
7 
8 struct Line3D;
9 struct Segment3D;
10 struct Plane3D;
11 struct AABB3D;
12 
21 struct Sphere3D
22 {
24  Real distance(const Point3D& v) const;
25  Real signedDistance(const Point3D& v) const;
26  bool contains(const Point3D& v) const;
27  bool contains(const Sphere3D& s) const;
28  bool withinDistance(const Point3D& v, Real dist) const;
29  Real closestPoint(const Point3D& in, Point3D& out) const;
30  bool boundaryWithinDistance(const Point3D& v, Real dist) const;
31  bool intersects(const Line3D&, Real* t1=NULL, Real* t2=NULL) const;
32  bool intersects(const Segment3D&, Real* t1=NULL, Real* t2=NULL) const;
33  bool intersects(const Plane3D& p) const;
34  bool intersects(const Sphere3D& s) const;
35  bool boundaryIntersects(const Sphere3D& s) const;
36  bool boundaryIntersectsBoundary(const Sphere3D& s) const;
37  bool Read(File& f);
38  bool Write(File& f) const;
39 
40  void getAABB(AABB3D& bb) const;
41  bool intersects(const AABB3D& bb) const;
42 
43  static bool ballsIntersect(const Point3D& ca,Real ra,const Point3D& cb,Real rb);
44  static bool ballSphereIntersect(const Point3D& ca,Real ra,const Point3D& cb,Real rb);
45  static bool spheresIntersect(const Point3D& ca,Real ra,const Point3D& cb,Real rb);
46 
47  Point3D center;
48  Real radius;
49 };
50 
51 } //namespace Math3D
52 
53 #endif
A 3D plane classRepresents plane with a normal and offset such that x on the plane satisfy dot(normal...
Definition: Plane3D.h:19
A 3D vector class.
Definition: math3d/primitives.h:136
A 3D axis-aligned bounding box.
Definition: AABB3D.h:13
A 3D sphere class.
Definition: Sphere3D.h:21
Contains all the definitions in the Math3D package.
Definition: AnyGeometry.h:13
A 3D line class.
Definition: Line3D.h:18
Real closestPoint(const Point3D &in, Point3D &out) const
Returns the distance from the sphere to in.
Definition: geometry3d.cpp:57
A cross-platform class for reading/writing binary data.
Definition: File.h:47
Definition: Segment3D.h:12
Real distance(const Point3D &v) const
Note: this is actually the signed distance.
Definition: geometry3d.cpp:32