Numerically compute intersection of infinite line and rectangle

287 Views Asked by At

I'm trying to numerically compute where an infinite line defined by two points intersects a (finite) rectangle also defined by two points. Here's a illustration of the various ways that the line can intersect the rectangle: A diagram showing "No intersections", "One intersection", "Two intersections", and "∞ intersections" How can I determine the number and location of the places where the infinite line intersects the rectangle? I know how to do this when the line is finite, but I can't figure out how to generalize that to an infinite context.

1

There are 1 best solutions below

0
On BEST ANSWER

Idea: find out on which side of the line the four corners lie

  • no corners on the line and
    • all four corners on one side: $0$ intersections
    • one corner on one side, three corners on the other side: $2$ intersections
    • two corners on one side, two on the other side: $2$ intersections
  • exactly one corner on the line and
    • three on one side: $1$ intersection
    • one on one side, two on the other sides: $2$ intersections
  • exactly two corners on the line and
    • they are diagonally opposite ones: $2$ intersections
    • they are adjacent ones: infinitely many intersections