Anonymous user
Ray-casting algorithm: Difference between revisions
m
→{{header|REXX}}: corrected a typo, changed some comments.
m (comment: edges not corners) |
m (→{{header|REXX}}: corrected a typo, changed some comments.) |
||
Line 2,525:
=={{header|REXX}}==
Over half of the REXX program is devoted to
<lang rexx>/*REXX
call points 5 5,
call polygon 0 0,
call polygon 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 polygon 0 0, 2.5 2.5, 0 10, 2.5 7.5, 7.5 7.5, 10 10, 10 0 ; call test 'irregular'
call polygon 3 0, 7 0, 10 5, 7 10, 3 10, 0 5 ; call test '
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
in_out: procedure expose point. poly.;
end /*side*/
/*────────────────────────────────────────────────────────────────────────────*/
points:
call value v'0',n
return
/*────────────────────────────────────────────────────────────────────────────*/
polygon:
do j=1 for arg(); n=n+1; _=arg(j); parse var
call value v||n'.X', word(_,1); call value v||n'.Y', word(_,2)
if n//2 then iterate
n=n+1
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;
/*────────────────────────────────────────────────────────────────────────────*/
ray_intersect: procedure expose point. poly.; parse arg ?,s; sp=s+1
Px=point.?.x; Py=point.?.y
Ax=poly.s.x; Bx=poly.sp.x
if Ay>By
if Py=Ay | Py=By
if Py<Ay | Py>By |
if Px<min(Ax,Bx)
if Ax\=Bx then m_red
else m_red=infinity
if Ax\=Px then m_blue
else return 1
/*────────────────────────────────────────────────────────────────────────────*/
say ' ['arg(1)"] point:" right(point.k.x','point.k.y, 9),▼
test: say; do k=1 for point.0; say right(' ['arg(1)"] point:",30),
" is " word('outside inside', in_out(k)+1)▼
end /*k*/▼
return</lang>▼
▲ end /*k*/
▲ return</lang>
'''output'''
<pre>
[square] point:
[square] point:
[square] point:
[square] point:
[square] point:
[square] point:
[square] point:
[square hole] point:
[square hole] point:
[square hole] point:
[square hole] point:
[square hole] point:
[square hole] point:
[square hole] point:
[irregular] point:
[irregular] point:
[irregular] point:
[irregular] point:
[irregular] point:
[irregular] point:
[irregular] point:
[
[
[
[
[
[
[
</pre>
|