|
|
There you go. Not really simpler but it wont give you divide by zero errors.
#macro LineIntersect2D(A,B,C,D)
#local det = (D.y-C.y)*(B.x-A.x)-(D.x-C.x)*(B.y-A.y);
#local c = (D.x-C.x)*(A.y-C.y)-(D.y-C.y)*(A.x-C.x);
#if(det != 0)
#local slope_intercept_x = A.x+c/det*(B.x-A.x);
#local slope_intercept_y = A.y+c/det*(B.y-A.y);
#else
#if(c != 0)
//handle parallel case
#else
//handle coincident case
#end
#end
<slope_intercept_x, slope_intercept_y>
#end
stbenge <myu### [at] hotmailcom> wrote:
> 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
|
|