Anonymous user
Ray-casting algorithm: Difference between revisions
m
→{{header|REXX}}: added whitespace, changed an indentation for alignment.
(Added Visual Basic .NET Translation.) |
m (→{{header|REXX}}: added whitespace, changed an indentation for alignment.) |
||
Line 3,100:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
in$out: procedure expose point. poly.;
return # // 2 /*ODD is inside. EVEN is outside.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
intersect: procedure expose point. poly.; parse arg ?,s; sp=s + 1
epsilon= '1e' || (-digits() %2);
Px=point.?.x; Ax=poly.s.x; Ay=poly.s.y
Py=point.?.y; Bx=poly.sp.x; By=poly.sp.y /* [↓] do a swap.*/
if Ay>By then parse value Ax Ay Bx By with Bx By Ax Ay
if Py=Ay | Py=By then Py=Py + epsilon
if Py<Ay | Py>By | Px>max(Ax, Bx) then return 0
if
if Ax\=Bx then m_red = (By-Ay) / (Bx-Ax)
else m_red = infinity
if Ax\=Px then m_blue= (Py-Ay) / (Px-Ax)
else return 1
return m_blue >= m_red
Line 3,125:
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
poly: @= 'POLY.';
n=0
do j=1 for arg(); n=n + 1;
call value @ || n'.X', xx ; call value @ || n".Y", yy
if n//2 then iterate; n=n + 1
call value @ || n'.X', xx ; call value @ || n".Y", yy
end /*j*/
n=n + 1
call value @ || n'.X', Fx; call value @ || n".Y", Fy;
return /*POLY.0 is # segments(sides).*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
test: say; do k=1 for point.0; w=wx + wy + 2
say right(' ['arg(1)"] point:", 30),
right( right(point.k.x, wx)', 'right(point.k.y, wy), w) " is ",
right( word('outside inside', in$out(k) + 1), 7)
end /*k*/
return</lang>
|