POV-Ray : Newsgroups : povray.binaries.images : Divide by negative zero : Re: Divide by negative zero Server Time
19 Apr 2024 14:44:28 EDT (-0400)
  Re: Divide by negative zero  
From: JimT
Date: 30 Oct 2018 05:55:01
Message: <web.5bd82976a617eb51be7517870@news.povray.org>
"Anthony D. Baye" <Sha### [at] spamnomorehotmailcom> wrote:
> What it should look like.
>
> Regards,
>
> A.D.B.

Anthony,

If you use the x(tVal1) = UI1 + Ud*tVal1 , y(tVal2) = VI1 + Vd*tVal2 formulation
for the lines then (x(tVal1)-y(tVal2)).Ud = 0 and
(x(tVal1)-y(tVal2)).Vd = 0 give 2 equations for tVal1 and tVal2. These would
give the nearest points of the pair of lines in 3D or the intersection point of
lines in 2D.

In the following, the only division is by detM, which will only be zero if the
lines are parallel. This will therefore not tread on the +-0 problem POV Ray
seems to have.

Thanks,

JimT

#macro IPoint(UI1, UI2, VI1, VI2)
  #local Ud      = vnormalize(UI2 - UI1);
  #local Vd      = vnormalize(VI2 - VI1);
  #local UddotVd = vdot(Ud,Vd);
  #if(UddotVd    = 1)
    #local rX    = 0;  // Parallel lines so no soln or infinite solns
    #local rY    = 0;
  #else
    #local UV1   = UI1 - VI1;
    #local b1    = vdot(-UV1,Ud);
    #local b2    = vdot( UV1,Vd);
    #local detM  = 1 - UddotVd*UddotVd;
    #local tVal  = (b1 + UddotVd*b2)/detM;
    #local Upt   = UI1 + Ud*tVal;
    #local rX    = Upt.x;
    #local rY    = Upt.y;
  #end
  #local retval  = <rX,rY, 0.0>;
  retval
#end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.