Jump to content
  • Advertisement
Sign in to follow this  
ClaF

line intersecting rectangle

This topic is 4811 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

Hi I have a rectangle and a line. The line is generated by knowing two vertexes and plotting a line between them. This results in the problem that the line itself will not be detected in any collisions without a special method. This special method is what I need help on. How do I find the intersection points (X and Y axis only since its 2D), of where the line cuts the rectangle. Also, if there are more than one intersection points, how do I find them all? Thanks for any help

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Here's a direct method that should be intuitive to you, although it won't be perfectly efficient. Consider a rectangle as a series of lines {l1 ... l4}. The intersection of a line with a line is straightforward; you're solving for two unknowns (the x, y coordinates of the intersection point) with two linear equations (the two lines). If you get more than one solution for a given line, then one of the lines of the rectangle is a line segment of the line you're testing. Otherwise, stop after you have two solutions; a given line can't intersect a given rectangle more than twice in two dimensions.

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!