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.
|