Ray-casting algorithm: Difference between revisions

added Ursala
(perl)
(added Ursala)
Line 820:
puts "$point in $poly = [point_in_polygon $point $poly]"
}</lang>
 
=={{header|Ursala}}==
This function takes a point (x,y) and a polygon <(x1,y1)...(xn,yn)>
to a true value if the point is enclosed by the polygon and a false
value if it's outside, using the algorithm described above.
For points on the boundary the result is unspecified.
<lang Ursala>#import flo
 
in =
 
@lrzyCipPX ~|afatPRZaq ~&EZ+fleq~~lrPrbr2G&& ~&B+fleq~~lrPrbl2G!| -&
~&Y+ ~~lrPrbl2G fleq,
^E(fleq@lrrPX,@rl fleq\0.)^/~&lr ^(~&r,times)^/minus@llPrll2X vid+ minus~~rbbI&-</lang>
This test program tries it on a couple of examples.
<lang Ursala>#cast %bL
 
examples =
 
in* <
((0.5,0.6),<(0.,0.),(1.,2.),(1.,0.)>),
((0.5,0.6),<(0.,0.),(1.,1.),(1.,0.)>)></lang>
output:
<pre><true,false></pre>
Anonymous user