found this on a web site , is it correct

This topic is 2900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

it is for line collision could some one look over lis cause i cant get it to work . just want to check if its just me being stupid, or is it some how incorrect please Line Intersection Collision Detection w = (b.y2 - b.y1) * (a.x2 - a.x1) - (b.x2 - b.x1) * (a.y2 - a.y1) if w = 0 then 'no intersection (parallel lines) v = (b.x2 - b.x1) * (a.y1 - b.y1) - (b.y2 - b.y1) * (a.x1 - b.x1) u = v / w The intersection point is then x = a.x1 + u * (a.x2 - a.x1) y = a.y1 + u * (a.y2 - a.y1) But this is for infinite lines, and you probably wanted to see if two segments intersected. This is done by checking that the intersection point lies on both of the segments. if x < a.x1 or x > a.x2 or y < a.y1 or x > a.x2 then 'no intersection if x < b.x1 or x > b.x2 or y < b.y1 or x > b.x2 then 'no intersection or check the w value if w < 0 or w > 1 then 'no intersection

Share on other sites
I just worked it out on paper, and this is what I got

$w = (B.x_2 - B.x_1)(A.y_2 - A.y_1) - (B.y_2 - B.y_1)(A.x_2 - A.x_1)$
$v = (B.y_1 - A.y_1)(B.x_2 - B.x_1)+(B.y_2 - B.y_1)(A.x_1 - B.x_1)$