|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |