Original Post
🔒 Locked
2D Line Intersection
Advertisement
something like that?
// ''plane'' from segment 1 (normal is perpendicular to segment)
Vector n0(v1.y - v2.y, v2.x - v1.x);
float d0 = v1.x*n0.x + v1.y*n0.y;
// ''plane'' from segment 2 (normal is perpendicular to segment)
Vector n1(v3.y - v4.y, v4.x - v3.x);
float d1 = v3.x*n1.x + v3.y*n1.y;
// sign of v1 and v2 from segment plane 2 (dot product)
float s1 = (v1.x*n1.x + v1.y*n1.y) - d1;
float s2 = (v2.x*n1.x + v2.y*n1.y) - d1;
// sign of v3 and v4 from segment plane 1
float s3 = (v3.x*n0.x + v3.y*n0.y) - d0;
float s4 = (v4.x*n0.x + v4.y*n0.y) - d0;
// segments don''t cross a plane, so they can''t intersect
if (sign(s1) == sign(s2)) return false;
if (sign(s3) == sign(s4)) return false;
return true;
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement