Ray-casting algorithm: Difference between revisions

Content added Content deleted
m (→‎{{header|C}}: removed old-work comments; alignment of \ into define)
m (a slightly better pseudo (correction for the vertex problem), and a typo fix (By instead of B))
Line 41: Line 41:
B : the end-point of the segment with the greatest y coordinate
B : the end-point of the segment with the greatest y coordinate
(B must be "above" A)
(B must be "above" A)
'''if''' Py Ay '''or''' Py B '''then'''
'''if''' Py = Ay '''or''' Py = By '''then'''
Py ← Py + ε
'''end''' '''if'''
'''if''' Py > Ay '''or''' Py < By '''then'''
'''return''' false
'''return''' false
'''else''' '''if''' Px > max(Ax, Bx) '''then'''
'''else''' '''if''' Px > max(Ax, Bx) '''then'''
Line 67: Line 70:
'''end''' '''if'''
'''end''' '''if'''


(As it can be seen, if the ray passes through a vertex, it is not considered intersection; there exists a set of "situations" where this behaviour brings to wrong results; to avoid this, we should "move" the point up or down by a small quantity)
(To avoid the "ray on vertex" problem, the point is moved upward of a small quantity &epsilon;)