Ray-casting algorithm: Difference between revisions

m
Fixed lang tags.
m (→‎{{header|Tcl}}: Better living through whitespaces)
m (Fixed lang tags.)
Line 438:
end program Pointpoly</lang>
=={{header|J}}==
<lang j>NB.*crossPnP v point in closed polygon, crossing number
<lang j>
NB.*crossPnP v point in closed polygon, crossing number
NB. bool=. points crossPnP polygon
crossPnP=: 4 : 0"2
Line 447 ⟶ 446:
p2=. (x0-/X) < (x0-x1) * (y0-/Y) % (y0 - y1)
2|+/ p1*.p2
)</lang j>
)
</lang>
 
Sample data:
<lang j>SQUAREV=: 0 0 , 10 0 , 10 10 ,: 0 10
<lang j>
SQUAREV=: 0 0 , 10 0 , 10 10 ,: 0 10
SQUAREV=: SQUAREV, 2.5 2.5 , 7.5 0.1 , 7.5 7.5 ,: 2.5 7.5
 
Line 462 ⟶ 459:
STRANGE=: (0 4,4 3,3 7,7 6,6 2,2 1,1 5,:5 0) , .{ SQUAREV
 
POINTS=: 5 5,5 8,2 2,0 0,10 10,2.5 2.5,0.01 5,2.2 7.4,0 5,10 5,:_4 10</lang>
</lang>
 
Testing:
<lang j> (<POINTS) crossPnP every ESA;SQUARE;SQUAREHOLE;STRANGE
<lang j>
(<POINTS) crossPnP every ESA;SQUARE;SQUAREHOLE;STRANGE
1 1 1 0 0 1 1 1 0 1 0
1 1 1 0 0 1 1 1 0 1 0
0 1 1 0 0 1 1 1 0 1 0
1 0 0 0 0 0 0 1 0 1 0</lang>
</lang>
 
=={{header|Perl}}==
Line 656 ⟶ 650:
for p in testpoints[3:6])
print ' ', '\t'.join("%s: %s" % (p, ispointinside(p, poly))
for p in testpoints[6:])</lang></div>
</lang></div>
 
'''Sample output'''
Anonymous user