IceBoundingSphere.h
Go to the documentation of this file.
1 
8 
11 // Include Guard
12 #ifndef __ICEBOUNDINGSPHERE_H__
13 #define __ICEBOUNDINGSPHERE_H__
14 
16  {
20 
21  BS_FORCE_DWORD = 0x7fffffff
22  };
23 
25  {
26  public:
30  inline_ Sphere(const Point& center, float radius) : mCenter(center), mRadius(radius) {}
32  Sphere(udword nb_verts, const Point* verts);
34  inline_ Sphere(const Sphere& sphere) : mCenter(sphere.mCenter), mRadius(sphere.mRadius) {}
37 
38  BSphereMethod Compute(udword nb_verts, const Point* verts);
39  bool FastCompute(udword nb_verts, const Point* verts);
40 
41  // Access methods
42  inline_ const Point& GetCenter() const { return mCenter; }
43  inline_ float GetRadius() const { return mRadius; }
44 
45  inline_ const Point& Center() const { return mCenter; }
46  inline_ float Radius() const { return mRadius; }
47 
48  inline_ Sphere& Set(const Point& center, float radius) { mCenter = center; mRadius = radius; return *this; }
49  inline_ Sphere& SetCenter(const Point& center) { mCenter = center; return *this; }
50  inline_ Sphere& SetRadius(float radius) { mRadius = radius; return *this; }
51 
53 
58  inline_ bool Contains(const Point& p) const
60  {
61  return mCenter.SquareDistance(p) <= mRadius*mRadius;
62  }
63 
65 
70  inline_ bool Contains(const Sphere& sphere) const
72  {
73  // If our radius is the smallest, we can't possibly contain the other sphere
74  if(mRadius < sphere.mRadius) return false;
75  // So r is always positive or null now
76  float r = mRadius - sphere.mRadius;
77  return mCenter.SquareDistance(sphere.mCenter) <= r*r;
78  }
79 
81 
86  inline_ BOOL Contains(const AABB& aabb) const
88  {
89  // I assume if all 8 box vertices are inside the sphere, so does the whole box.
90  // Sounds ok but maybe there's a better way?
91  float R2 = mRadius * mRadius;
92 #ifdef USE_MIN_MAX
93  const Point& Max = ((ShadowAABB&)&aabb).mMax;
94  const Point& Min = ((ShadowAABB&)&aabb).mMin;
95 #else
96  Point Max; aabb.GetMax(Max);
97  Point Min; aabb.GetMin(Min);
98 #endif
99  Point p;
100  p.x=Max.x; p.y=Max.y; p.z=Max.z; if(mCenter.SquareDistance(p)>=R2) return FALSE;
101  p.x=Min.x; if(mCenter.SquareDistance(p)>=R2) return FALSE;
102  p.x=Max.x; p.y=Min.y; if(mCenter.SquareDistance(p)>=R2) return FALSE;
103  p.x=Min.x; if(mCenter.SquareDistance(p)>=R2) return FALSE;
104  p.x=Max.x; p.y=Max.y; p.z=Min.z; if(mCenter.SquareDistance(p)>=R2) return FALSE;
105  p.x=Min.x; if(mCenter.SquareDistance(p)>=R2) return FALSE;
106  p.x=Max.x; p.y=Min.y; if(mCenter.SquareDistance(p)>=R2) return FALSE;
107  p.x=Min.x; if(mCenter.SquareDistance(p)>=R2) return FALSE;
108 
109  return TRUE;
110  }
111 
113 
118  inline_ bool Intersect(const Sphere& sphere) const
120  {
121  float r = mRadius + sphere.mRadius;
122  return mCenter.SquareDistance(sphere.mCenter) <= r*r;
123  }
124 
126 
130  inline_ BOOL IsValid() const
132  {
133  // Consistency condition for spheres: Radius >= 0.0f
134  if(mRadius < 0.0f) return FALSE;
135  return TRUE;
136  }
137  public:
139  float mRadius;
140  };
141 
142 #endif // __ICEBOUNDINGSPHERE_H__
#define FALSE
Definition: OPC_IceHook.h:9
inline_ ~Sphere()
Destructor.
inline_ void GetMin(Point &min) const
Get min point of the box.
Definition: IceAABB.h:343
#define TRUE
Definition: OPC_IceHook.h:13
#define inline_
float z
Definition: IcePoint.h:524
Definition: IcePoint.h:25
#define ICEMATHS_API
Definition: OPC_IceHook.h:51
inline_ Sphere & SetRadius(float radius)
inline_ Sphere & SetCenter(const Point &center)
inline_ const Point & Center() const
inline_ Sphere()
Constructor.
int BOOL
Another boolean type.
Definition: IceTypes.h:102
float x
Definition: IcePoint.h:524
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
inline_ float Radius() const
inline_ Sphere(const Point &center, float radius)
Constructor.
inline_ const Point & GetCenter() const
Definition: IceAABB.h:267
inline_ void GetMax(Point &max) const
Get max point of the box.
Definition: IceAABB.h:345
float mRadius
Sphere radius.
Point mCenter
Sphere center.
inline_ Sphere & Set(const Point &center, float radius)
float y
Definition: IcePoint.h:524
inline_ float GetRadius() const
inline_ Sphere(const Sphere &sphere)
Copy constructor.
inline_ BOOL Intersect(const AABB &a, const SAP_Box &b)
BSphereMethod


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:03