POV-Ray : Newsgroups : povray.general : Looking for a formula : Re: Looking for a formula Server Time
29 Jul 2024 12:17:03 EDT (-0400)
  Re: Looking for a formula  
From: clipka
Date: 15 Feb 2013 11:04:58
Message: <511e5caa$1@news.povray.org>
Am 15.02.2013 15:24, schrieb Trevor G Quayle:

> OK, if it is a pair of 2d lines, you just need to solve for the two line
> equations, then solve for the intersection:
>
> General 2-d line equation is "y = mx + b"

... and isn't as general as would be desirable, because it doesn't work 
for vertical lines.

> Or to really simplify it, we can combine all of the above and get formulae to
> solve directly for x and y from the points:
>
> xi =
>
[(x21-x22)*(x11*y12-x12*y11)+(x11-x12)*(x22*y21-x21*y22)]/[(x21-x22)*(y12-y11)+(x11-x12)(y21-y22)]

That's a clean, nice & safe term. Note how the denominator is fully 
symmetric with respect to both x vs. y as well as line 1 vs. line 2, 
indicating that there won't be any problems with vertical lines.

> yi = (xi-x11)*(y12-y11)/(x12-x11)+y11

Better use the term symmetric to the one used for xi, i.e.:

yi = 
[(y21-y22)*(y11*x12-y12*x11)+(y11-y12)*(y22*x21-y21*x22)]/[(y21-y22)*(x12-x11)+(y11-y12)(x21-x22)]

(Note that the denominator term is the same as for xi except for the 
sign, so you can save a few computations there.)

While this requires a few more computation steps, it avoids the problem 
of vertical lines once again, and gives more precise results for 
near-vertical lines.


Post a reply to this message

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