POV-Ray : Newsgroups : povray.advanced-users : Divide by zero : Re: Divide by zero Server Time
29 Jun 2024 01:48:45 EDT (-0400)
  Re: Divide by zero  
From: stbenge
Date: 20 Jul 2010 00:36:23
Message: <4c4527c7@news.povray.org>
Roman Reiner wrote:
> You should use 2D vectors rather than slopes. That way "infinite slope" is just
> the vector <0,1> which can be used in calculations without problems.

It's probably easier than I think, but I was rushing to get to the good 
part and just plugged in a formula:

#macro LineIntersect2D(A,B,C,D)
  #local m1 = (A.y-B.y)/(A.x-B.x);
  #local m2 = (C.y-D.y)/(C.x-D.x);
  #local b1 = A.y - m1*A.x;
  #local b2 = C.y - m2*C.x;
  #local slope_intercept_x = (b2-b1)/(m1-m2);
  #local slope_intercept_y = m1*slope_intercept_x + b1;
  <slope_intercept_x, slope_intercept_y>
#end

That's minus the #if statements I put in there as a patch. I'm sure 
there's a much simpler solution, but my momentum has been sending me 
toward farther goals, so I haven't worked it out yet.


Post a reply to this message

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