View Single Post
Old 01-29-2003, 02:19 AM   #9
Teelf
Member
 
Join Date: Apr 2002
Location: Seattle
Posts: 32
Teelf is on a distinguished road
Determining if a point intersects a sphere requires only one check.

[code] bool Sphere;;Intersects(const Vector& point)
{
float flSqrDist = SqrDistance(_vecCenter, point);
return (flSqrDist < (_flRad*_flRad));
}[/quote]

With SqrDistance returning the squared distance from the sphere's center to the point in question. And _flRad is the sphere's radius.

No square roots and only 1 check versus 6 for a rectangle.  Spheres are computationally cheaper than rectangles in almost any use.

NOTE: In case people are thinking this is about graphics, it's not.  This is all very applicable to text MUDs.
Teelf is offline   Reply With Quote