Ray-casting algorithm: Difference between revisions

m
→‎{{header|REXX}}: aligned the points and vertices better.
m (→‎{{header|REXX}}: added a "swap" comment.)
m (→‎{{header|REXX}}: aligned the points and vertices better.)
Line 2,532:
seems to indicate that this code considers those points as outside the polygon.
<lang rexx>/*REXX pgm checks to see if a horizontal ray from point P intersects a polygon*/
call points 5 5, 5 8, -10 5, 0 5, 10 5, 8 5, 10 10
callA=2.5; polygon B=7.5 0 0, 10 0, 10 10, 0 10 /*◄───for shorter ; call test 'square'args*/
call polygon poly 0 0, 10 0, 10 10, 0 10, 2.5 2.5, 7.5 2.5, 7.5 7.5, 2.5 7.5 ; call test 'square hole'
call polygonpoly 0 0, 10 0, 2.510 2.510, 0 10, A 2.5 7.5A, 7.5B 7.5 A, 10 10,B 10B, 0A B ; call test 'irregular'square hole
call polygonpoly 30 0, 7A 0A, 0 10 5, A 7 10B, 3B 10B, 10 0 5 10, 10 0 ; call test 'hexagonirregular'
call poly 3 0, 7 0, 10 5, 7 10, 3 10, 0 5 ; call test 'hexagon'
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
Line 2,551 ⟶ 2,552:
return
/*────────────────────────────────────────────────────────────────────────────*/
polygonpoly: n=0; v='POLY.'; parse arg Fx Fy /* [↓] process the X,Y points*/
 
do j=1 for arg(); n=n+1; _=arg(j); parse var _ xx yy
Line 2,559 ⟶ 2,560:
call value v||n'.X', word(_,1); call value v||n'.Y', word(_,2)
end /*j*/
n=n+1
call value v||n".X", Fx; call value v||n".Y", Fy; call value v'0',n
return /*POLY.0 is number of segments/sides.*/
/*────────────────────────────────────────────────────────────────────────────*/
ray_intersect: procedure expose point. poly.; parse arg ?,s; sp=s+1
epsilon='1e' || (digits()%2); infinity='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*/