Simbody  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimTK::Geo::Box_< P > Class Template Reference

A 3d rectangular box aligned with an unspecified frame F and centered at that frame's origin. More...

#include <Geo.h>

Public Member Functions

 Box_ ()
 Construct an uninitialized Box object; the dimensions will be garbage. More...
 
 Box_ (const Vec3P &halfLengths)
 Construct a Box with the given nonnegative half-dimensions. More...
 
Box_setHalfLengths (const Vec3P &halfLengths)
 Change the half-dimensions of this box. More...
 
Box_addToHalfLengths (const Vec3P &incr)
 Change the half-dimensions of this box by adding the given vector. More...
 
const Vec3PgetHalfLengths () const
 Return the half-lengths of this box as a Vec3 from the center to the first quadrant vertex. More...
 
RealP getOrderedHalfLength (int i) const
 Get lengths in order shortest to longest; 0 is shortest, 2 is longest. More...
 
CoordinateAxis getOrderedAxis (int i) const
 Get axes in order shortest to longest; 0 is shortest, 2 is longest. More...
 
RealP findVolume () const
 Calculate the volume of this box. More...
 
RealP findArea () const
 Calculate the surface area of this box, ignoring degeneracy (meaning that all pairs of sides are counted even if coincident). More...
 
bool containsPoint (const Vec3P &pt) const
 Given a point measured and expressed in the box frame, determine whether it is inside the box (we count touching the surface as inside). More...
 
RealP findDistanceSqrToPoint (const Vec3P &pt) const
 Return the square of the distance from this box to a given point whose location is measured from and expressed in the box frame (at the box center). More...
 
RealP findDistanceSqrToSphere (const Geo::Sphere_< P > &sphere) const
 Return the square of the distance from this box to a given sphere whose center location is measured from and expressed in the box frame (at the box center). More...
 
RealP findDistanceSqrToAlignedBox (const Geo::AlignedBox_< P > &aab) const
 Return the square of the distance from this box to an axis-aligned box whose center location is measured from and expressed in this box frame (at the box center). More...
 
bool intersectsSphere (const Geo::Sphere_< P > &sphere) const
 Given a sphere with center measured and expressed in the box frame, return true if the box and sphere intersect. More...
 
bool intersectsAlignedBox (const Geo::AlignedBox_< P > &aab) const
 Given an aligned box with center measured and expressed in the from of this box, return true if the two boxes intersect. More...
 
bool intersectsOrientedBox (const Geo::OrientedBox_< P > &ob) const
 Given an oriented box whose pose is measured and expressed in the frame of this box, return true if the two boxes intersect. More...
 
bool mayIntersectOrientedBox (const Geo::OrientedBox_< P > &ob) const
 Given an oriented box whose pose is measured and expressed in the frame of this box, return true if the two boxes may be intersecting. More...
 

Detailed Description

template<class P>
class SimTK::Geo::Box_< P >

A 3d rectangular box aligned with an unspecified frame F and centered at that frame's origin.

The box has a local frame B, centered at the box center and oriented along the box edges, and B==F. We keep track of the relative edge lengths to facilitate short-to-long processing.

Constructor & Destructor Documentation

template<class P >
SimTK::Geo::Box_< P >::Box_ ( )
inline

Construct an uninitialized Box object; the dimensions will be garbage.

template<class P >
SimTK::Geo::Box_< P >::Box_ ( const Vec3P halfLengths)
inline

Construct a Box with the given nonnegative half-dimensions.

Cost is 4 flops to sort the edges.

Member Function Documentation

template<class P >
Box_& SimTK::Geo::Box_< P >::setHalfLengths ( const Vec3P halfLengths)
inline

Change the half-dimensions of this box.

Dimensions must be nonnegative. Cost is 4 flops to sort the edges.

template<class P >
Box_& SimTK::Geo::Box_< P >::addToHalfLengths ( const Vec3P incr)
inline

Change the half-dimensions of this box by adding the given vector.

The result must be nonnegative. Cost is 7 flops, including resorting the edges.

template<class P >
const Vec3P& SimTK::Geo::Box_< P >::getHalfLengths ( ) const
inline

Return the half-lengths of this box as a Vec3 from the center to the first quadrant vertex.

template<class P >
RealP SimTK::Geo::Box_< P >::getOrderedHalfLength ( int  i) const
inline

Get lengths in order shortest to longest; 0 is shortest, 2 is longest.

template<class P >
CoordinateAxis SimTK::Geo::Box_< P >::getOrderedAxis ( int  i) const
inline

Get axes in order shortest to longest; 0 is shortest, 2 is longest.

template<class P >
RealP SimTK::Geo::Box_< P >::findVolume ( ) const
inline

Calculate the volume of this box.

Cost is 4 flops.

template<class P >
RealP SimTK::Geo::Box_< P >::findArea ( ) const
inline

Calculate the surface area of this box, ignoring degeneracy (meaning that all pairs of sides are counted even if coincident).

Cost is 6 flops.

template<class P >
bool SimTK::Geo::Box_< P >::containsPoint ( const Vec3P pt) const
inline

Given a point measured and expressed in the box frame, determine whether it is inside the box (we count touching the surface as inside).

The point must be measured from the box center. Cost is about 5 flops.

template<class P >
RealP SimTK::Geo::Box_< P >::findDistanceSqrToPoint ( const Vec3P pt) const
inline

Return the square of the distance from this box to a given point whose location is measured from and expressed in the box frame (at the box center).

If the point is on or inside the box the returned distance is zero. Cost is about 14 flops.

template<class P >
RealP SimTK::Geo::Box_< P >::findDistanceSqrToSphere ( const Geo::Sphere_< P > &  sphere) const
inline

Return the square of the distance from this box to a given sphere whose center location is measured from and expressed in the box frame (at the box center).

If the sphere intersects the box the returned distance is zero. Cost is about 17 flops.

template<class P >
RealP SimTK::Geo::Box_< P >::findDistanceSqrToAlignedBox ( const Geo::AlignedBox_< P > &  aab) const
inline

Return the square of the distance from this box to an axis-aligned box whose center location is measured from and expressed in this box frame (at the box center).

If the boxes intersect the returned distance is zero. Cost is about 17 flops.

template<class P >
bool SimTK::Geo::Box_< P >::intersectsSphere ( const Geo::Sphere_< P > &  sphere) const
inline

Given a sphere with center measured and expressed in the box frame, return true if the box and sphere intersect.

We are treating both objects as solids, so we'll say yes even if one object completely contains the other. We also return true if they are just touching. Cost is about 8 flops.

template<class P >
bool SimTK::Geo::Box_< P >::intersectsAlignedBox ( const Geo::AlignedBox_< P > &  aab) const
inline

Given an aligned box with center measured and expressed in the from of this box, return true if the two boxes intersect.

We are treating both objects as solids, so we'll say yes even if one box completely contains the other. We also return true if they are just touching. Cost is about 8 flops.

template<class P >
bool SimTK::Geo::Box_< P >::intersectsOrientedBox ( const Geo::OrientedBox_< P > &  ob) const

Given an oriented box whose pose is measured and expressed in the frame of this box, return true if the two boxes intersect.

We are treating both objects as solids, so we'll say yes even if one box completely contains the other. We also return true if they are just touching. This is an exact but fairly expensive test if the boxes are separated; if you don't mind some false positives, use mayIntersectOrientedBox() instead. Cost is about 200 flops worst case (when boxes are intersecting) although it can return false in as few as 16 flops.

template<class P >
bool SimTK::Geo::Box_< P >::mayIntersectOrientedBox ( const Geo::OrientedBox_< P > &  ob) const

Given an oriented box whose pose is measured and expressed in the frame of this box, return true if the two boxes may be intersecting.

Only relatively cheap operations are performed at the expense of returning false positives sometimes (allegedly less than 10% of the time). If you need an exact determination, use intersectsOrientedBox(). Cost is about 75 flops worst case (when boxes appear to be intersecting) but can return false in as few as 16 flops.


The documentation for this class was generated from the following files: