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__
Sphere::Center
const inline_ Point & Center() const
Definition: IceBoundingSphere.h:45
Sphere::mCenter
Point mCenter
Sphere center.
Definition: IceBoundingSphere.h:138
Point::z
float z
Definition: IcePoint.h:524
Sphere::Set
inline_ Sphere & Set(const Point &center, float radius)
Definition: IceBoundingSphere.h:48
udword
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
BOOL
int BOOL
Another boolean type.
Definition: IceTypes.h:102
swingTest.f
f
Definition: swingTest.py:6
Point::x
float x
Definition: IcePoint.h:524
Sphere::GetCenter
const inline_ Point & GetCenter() const
Definition: IceBoundingSphere.h:42
BS_MINIBALL
@ BS_MINIBALL
Definition: IceBoundingSphere.h:19
Sphere::SetRadius
inline_ Sphere & SetRadius(float radius)
Definition: IceBoundingSphere.h:50
Sphere::SetCenter
inline_ Sphere & SetCenter(const Point &center)
Definition: IceBoundingSphere.h:49
Sphere::~Sphere
inline_ ~Sphere()
Destructor.
Definition: IceBoundingSphere.h:36
Intersect
inline_ BOOL Intersect(const AABB &a, const SAP_Box &b)
Definition: OPC_SweepAndPrune.cpp:522
Sphere::Sphere
inline_ Sphere(const Sphere &sphere)
Copy constructor.
Definition: IceBoundingSphere.h:34
TRUE
#define TRUE
Definition: OPC_IceHook.h:13
BS_FORCE_DWORD
@ BS_FORCE_DWORD
Definition: IceBoundingSphere.h:21
ICEMATHS_API
#define ICEMATHS_API
Definition: OPC_IceHook.h:51
FALSE
#define FALSE
Definition: OPC_IceHook.h:9
Point
Definition: IcePoint.h:25
Sphere::Sphere
inline_ Sphere()
Constructor.
Definition: IceBoundingSphere.h:28
Sphere
Definition: IceBoundingSphere.h:24
Sphere::mRadius
float mRadius
Sphere radius.
Definition: IceBoundingSphere.h:139
BS_GEMS
@ BS_GEMS
Definition: IceBoundingSphere.h:18
Point::y
float y
Definition: IcePoint.h:524
AABB::GetMin
inline_ void GetMin(Point &min) const
Get min point of the box.
Definition: IceAABB.h:343
BS_NONE
@ BS_NONE
Definition: IceBoundingSphere.h:17
BSphereMethod
BSphereMethod
Definition: IceBoundingSphere.h:15
Sphere::Radius
inline_ float Radius() const
Definition: IceBoundingSphere.h:46
Sphere::Sphere
inline_ Sphere(const Point &center, float radius)
Constructor.
Definition: IceBoundingSphere.h:30
Sphere::GetRadius
inline_ float GetRadius() const
Definition: IceBoundingSphere.h:43
AABB::GetMax
inline_ void GetMax(Point &max) const
Get max point of the box.
Definition: IceAABB.h:345
inline_
#define inline_
Definition: IcePreprocessor.h:103
AABB
Definition: IceAABB.h:267


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