Moby
BoundingSphere.h
1 /****************************************************************************
2  * Copyright 2009 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef _MOBY_BSPHERE_H_
8 #define _MOBY_BSPHERE_H_
9 
10 #include <Moby/BV.h>
11 #include <Moby/DummyBV.h>
12 
13 namespace Moby {
14 
16 class BoundingSphere : public BV
17 {
18  public:
20  BoundingSphere(const BoundingSphere& bsphere) { operator=(bsphere); }
21  BoundingSphere(const Point3d& center, double radius);
22  BoundingSphere& operator=(const BoundingSphere& bsphere);
23  virtual void transform(const Ravelin::Transform3d& T, BV* result) const;
24  virtual std::ostream& to_vrml(std::ostream& out, const Ravelin::Pose3d& T) const;
25  virtual BVPtr calc_swept_BV(CollisionGeometryPtr g, const Ravelin::SVelocityd& v) const;
26  static double calc_dist(const BoundingSphere& s1, const BoundingSphere& s2);
27  static bool intersects(const BoundingSphere& a, const BoundingSphere& b);
28  static bool intersects(const BoundingSphere& a, const BoundingSphere& b, const Ravelin::Transform3d& aTb);
29  static bool intersects(const BoundingSphere& a, const LineSeg3& seg, double& tmin, double tmax, Point3d& q);
30  static bool outside(const BoundingSphere& a, const Point3d& point, double tol = NEAR_ZERO);
31  virtual bool outside(const Point3d& point, double tol = NEAR_ZERO) const { return BoundingSphere::outside(*this, point, tol); }
32  virtual bool intersects(const LineSeg3& seg, double& tmin, double tmax, Point3d& q) const { return BoundingSphere::intersects(*this, seg, tmin, tmax, q); }
33 
34  template <class ForwardIterator>
35  BoundingSphere(ForwardIterator begin, ForwardIterator end);
36 
38  virtual boost::shared_ptr<const Ravelin::Pose3d> get_relative_pose() const { return center.pose; }
39 
41  virtual Point3d get_lower_bounds() const { return Point3d(center[0]-radius, center[1]-radius, center[2] - radius, center.pose); }
42 
44  virtual Point3d get_upper_bounds() const { return Point3d(center[0]+radius, center[1]+radius, center[2] + radius, center.pose); }
45 
48 
50  double radius;
51 
53  virtual double calc_volume() const { return M_PI * radius * radius * radius; }
54 }; // end class
55 
56 // inline functions
57 #include "BoundingSphere.inl"
58 
59 } // end namespace
60 
61 #endif
62 
virtual BVPtr calc_swept_BV(CollisionGeometryPtr g, const Ravelin::SVelocityd &v) const
Calculates the velocity expanded bounding volume for the bounding sphere (calculates an OBB) ...
Definition: BoundingSphere.cpp:72
boost::shared_ptr< BV > BVPtr
Bounding volume (BV) smart pointer.
Definition: Types.h:92
virtual double calc_volume() const
Calculates the volume of this bounding volume.
Definition: BoundingSphere.h:53
virtual void transform(const Ravelin::Transform3d &T, BV *result) const
Transforms the BoundingSphere using the given transform.
Definition: BoundingSphere.cpp:35
static bool intersects(const BoundingSphere &a, const BoundingSphere &b)
Determines whether two bounding spheres intersect.
Definition: BoundingSphere.cpp:99
An abstract bounding volume.
Definition: BV.h:38
Point3d center
Center of the bounding box.
Definition: BoundingSphere.h:47
virtual Point3d get_upper_bounds() const
Gets the upper bounds on the bounding sphere.
Definition: BoundingSphere.h:44
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
virtual Point3d get_lower_bounds() const
Gets the lower bounds on the bounding sphere.
Definition: BoundingSphere.h:41
virtual bool outside(const Point3d &point, double tol=NEAR_ZERO) const
Determines whether a point is outside the bounding volume.
Definition: BoundingSphere.h:31
Ravelin::Vector3d Point3d
Typedef to distinguish between a 3D vector and a point.
Definition: Types.h:47
static bool outside(const BoundingSphere &a, const Point3d &point, double tol=NEAR_ZERO)
Determines whether a point is outside of the bounding sphere.
Definition: BoundingSphere.cpp:139
virtual bool intersects(const LineSeg3 &seg, double &tmin, double tmax, Point3d &q) const
Determines whether a line segment intersects the bounding volume.
Definition: BoundingSphere.h:32
virtual boost::shared_ptr< const Ravelin::Pose3d > get_relative_pose() const
Gets the pose for this BV.
Definition: BoundingSphere.h:38
std::pair< Point3d, Point3d > LineSeg3
Typedef to make specifying line segments easier.
Definition: Types.h:50
A sphere used for bounding geometry.
Definition: BoundingSphere.h:16
virtual std::ostream & to_vrml(std::ostream &out, const Ravelin::Pose3d &T) const
Sends the bounding sphere to VRML.
Definition: BoundingSphere.cpp:48
double radius
The radius of the bounding sphere (we use a float b/c accuracy here not so important) ...
Definition: BoundingSphere.h:50
static double calc_dist(const BoundingSphere &s1, const BoundingSphere &s2)
Calculates the signed distance between two bounding spheres.
Definition: BoundingSphere.cpp:128