Ray-casting algorithm: Difference between revisions

m
added whitespace to the task's preamble, enlarged a Greek glyph.
m (→‎{{header|Go}}: oops, missed close tag)
m (added whitespace to the task's preamble, enlarged a Greek glyph.)
Line 1:
{{task|Classic CS problems and programs}}
{{Wikipedia|Point_in_polygon}}
 
Given a point and a polygon, check if the point is inside or outside the polygon using the [[wp:Point in polygon#Ray casting algorithm|ray-casting algorithm]].
 
Line 29 ⟶ 30:
[[Image:posslope.png|128px|thumb|right]]
[[Image:negslope.png|128px|thumb|right]]
 
Let us take into account a segment AB (the point A having y coordinate always smaller than B's y coordinate, i.e. point A is always below point B) and a point P. Let us use the cumbersome notation PAX to denote the angle between segment AP and AX, where X is always a point on the horizontal line passing by A with x coordinate bigger than the maximum between the x coordinate of A and the x coordinate of B. As explained graphically by the figures on the right, if PAX is greater than the angle BAX, then the ray starting from P intersects the segment AB. (In the images, the ray starting from P<sub>A</sub> does not intersect the segment, while the ray starting from P<sub>B</sub> in the second picture, intersects the segment).
 
Line 70 ⟶ 72:
'''end''' '''if'''
 
(To avoid the "ray on vertex" problem, the point is moved upward of a small quantity &nbsp; <big>&epsilon;</big>.)
<br><br>
 
=={{header|Ada}}==