found this on a web site , is it correct

Started by
0 comments, last by Eric_Brown 14 years, 1 month ago
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
Advertisement
I just worked it out on paper, and this is what I got



This topic is closed to new replies.

Advertisement