1
votes

In matlab, how can I decide whether a line intersects with a rectangle or not ?

Lines and rectangle

For example the upper line is not intersecting with the rectangle and the two lower ones do,

Then: How can I decide the existence of the intersection from knowing two points of the line and another two points from the rectangle ?

My work:

Way 1: I am trying to solve the two equations of the line and the diagonal of the rectangle then check the solution point if it's within the rectangle or not.

1
I've tried some trigonometric calculation, I will prepare them then append them to the question. - Sameh Kamal

1 Answers

0
votes

The line and rectangle intersect if the line intersects with any side of the rectangle. All you need is a line/line intersection algorithm. For help with that, try searching here or elsewhere on the net.