> double Mass::intersect(Vector origin, Vector direction) const
> {
> Vector relPosition = position - origin;
> double radius2 = radius * radius;
> double nearestPointDistance = relPosition*direction;
>
> double halfChord2 = radius2 - relPosition*relPosition +
> nearestPointDistance*nearestPointDistance;
>
> if(halfChord2 > 0.0)
> {
> double nearPoint = nearestPointDistance - sqrt(halfChord2);
> double farPoint = nearestPointDistance + sqrt(halfChord2);
> if(nearPoint > EPSILON)
> return nearPoint;
> else
> return farPoint;
> }
> else
> return -1.0;
> }
Is this what POV-Ray actually uses for the intersection of a ray and a
sphere? I just spent half an hour working out both the geometrical
interpretation of this and its equivalence to the result of the quadratic
equation with the coefficients that Andrew posted, and I'm really impressed
at how simple it is. And annoyed at the fact that I never could have come up
with it myself =)
- Slime
[ http://www.slimeland.com/ ]
Post a reply to this message
|