Sign in to follow this  
the dodger uk

found this on a web site , is it correct

Recommended Posts

the dodger uk    148
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this