line intersecting rectangle
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
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement