|
|
I have two macros that calculate the intersection of two lines and
return a 2D vector <x,y>.
################################################
#macro line(p1, p2)
#local A = (p1.y - p2.y);
#local B = (p2.x - p1.x);
#local C = (p1.x * p2.y - p2.x*p1.y);
<A,B,-C>
#end
#macro line_intersection(l1, l2)
#local D = l1.x * l2.y - l1.y * l2.x;
#local Dx = l1.z * l2.y - l1.y * l2.z;
#local Dy = l1.x * l2.z - l1.z * l2.x;
#if (D != 0)
#local out_x = Dx / D;
#local out_y = Dy / D;
#local out_value = <out_x,out_y>;
#else
#local out_value = false;
#end
out_value
#end
#declare L1 = line(<0,1>, <2,3>);
#declare L2 = line(<2,3>, <0,4>);
#declare R = line_intersection(L1, L2);
//#if (R != false)
#debug concat("\n\n\nIntersection detected: <", vstr(2,R,",",0,-1),
">\n\n\n")
//#else
// #debug concat"No single intersection point detected")
//#end
################################################
Normally this works okay, but it is possible for the macro to fail if
the lines are coinciding. But, how can I signal a failure? I tried
passing the result to a conditional statement, but POVRay then complains
that it needs a float value but got a color value. There also is no
"null" or "undefined" value in POVRay SDL. I would appreciate some tips,
thanks.
Mike
Post a reply to this message
|
|