Ray-casting algorithm: Difference between revisions

→‎{{header|C}}: added "move the point if the ray is aligned with a vertex" fix + "exagon" which showed the problem in (5,5)
m (a slightly better pseudo (correction for the vertex problem), and a typo fix (By instead of B))
(→‎{{header|C}}: added "move the point if the ray is aligned with a vertex" fix + "exagon" which showed the problem in (5,5))
Line 97:
{0,0}, {10,0}, {10,10}, {0,10},
{2.5,2.5}, {7.5,0.1}, {7.5,7.5}, {2.5,7.5}
};
 
point_t esa_v[] =
{
{3,0}, {7,0}, {10,5}, {7,10}, {3,10}, {0,5}
};
 
polygon_t esa =
{
esa_v,
{ 0,1, 1,2, 2,3, 3,4, 4,5, 5,0, -1 }
};
 
Line 124 ⟶ 135:
#define minP(A,B,C) ( (((A)->C) > ((B)->C)) ? (B) : (A) )
#define coeff_ang(PA,PB) ( ((PB)->y - (PA)->y) / ((PB)->x - (PA)->x) )
#define EPS 0.00001
inline bool hseg_intersect_seg(point_t *s, point_t *a, point_t *b)
{
double eps = 0.0;
if ( (s->y >= MAX(a->y, b->y) ||
if ( s->y <== MINMAX(a->y, b->y)) ||
(s->xy >== MAXMIN(a->xy, b->xy) ) eps = EPS;
if ( (s->y + eps) >= MAX(a->y, b->y) ||
) return false;
(s->y + eps) < MIN(a->y, b->y) ||
s->x > MAX(a->x, b->x) ) return false;
if ( s->x <= MIN(a->x, b->x) ) return true;
double ca = (a->x != b->x) ? coeff_ang(a,b) :