|
![](/i/fill.gif) |
In article <web.3e1905318bb9cc14b417814a0@news.povray.org>,
"Tor Olav Kristensen" <tor### [at] hotmail com> wrote:
> I think this line;
> #local lRayStart = rayStart - midPt;
>
> - should have been:
> #local lRayStart = midPt - rayStart;
No, I don't think so. That code is transforming the ray by the inverse
of a transformation that would translate the plane to its position. This
is simply a subtraction from the ray origin.
> And there should be no need to normalize the normal vector.
There is. If the normal is twice as long, the intersection will be found
twice as far away. This could be with the exact same plane, and is
obviously wrong.
> Here's how I would have written that macro:
Well, remember that I was writing it to both fit in the message and more
to explain something than to be used.
> And here's how I would test the ray:
>
> #declare pHit = CompPoint(p0, p1, pRay, vRay);
>
> #if (vdot(pHit - pRay, vRay) < 0)
> #debug "There is no point on the ray that has"
> #debug "equal distances to both points."
> #end
Needlessly complex, but it would work. Here's what I'd use (still highly
simplified and spread out, though):
#macro CompPoint(pA, pB, rayStart, rayDir, Res)
// The midpoint and plane normal.
#local midPt = (pA + pB)/2;
#local Norm = vnormalize(pB - pA);
// Compensate for the plane not passing through the origin.
#local lRayStart = rayStart - midPt;
// Solve for intersection distance with line.
#local T = (vdot(Norm, lRayStart)/vdot(Norm, rayDir))
// If T is > 0, there is a ray intersection at rayStart + rayDir*T.
// Otherwise, no intersection.
#local isectFound = T > 0;
#if(isectFound)
#declare Res = rayStart + rayDir*T;
#end
(isectFound)
#end
#declare hitPoint = < 0, 0, 0>;
#if(CompPoint(pA, pB, rayStart, rayDir, hitPoint))
...
#end
Just for fun, a possible over-verbose Sapphire version:
method ComputePoint: result EquidistantTo: pA And: pB AlongRay: ray {
def midPt: (pA + pB)/2;
def norm: (pB - pA).(Normalize);
def t: norm.(Dot: ray.origin - midPt)/norm.(Dot: ray.direction);
if(t > 0) {
result = ray.(Evaluate: t);
return true;
}
else {
return false;
}
}
def pt: Vector.(Clone);
if(.(ComputePoint: pt EquidistantTo: pA And: pB AlongRay:
Ray.(RayWithOrigin: orig Direction: dir)))
...
(I wouldn't seriously use "ComputePoint:EquidistantTo:And:AlongRay:",
though...just self-documentation to an extreme. Some Objective-C method
names get even longer, though...)
--
Christopher James Huff <cja### [at] earthlink net>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tag povray org
http://tag.povray.org/
Post a reply to this message
|
![](/i/fill.gif) |