Jump to content
  • Advertisement
Sign in to follow this  
the dodger uk

found this on a web site , is it correct

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!