How to detect if there is an object between two points in a 2D plane?

196 Views Asked by At

I created a 2D plane using matplotlib and have generated a user-entered amount of randomly placed triangles. Given two(2) random points, an origin, and an endpoint, how would I go about detecting if the line segment created would touch or intersect one of the shapes? In the photo provided, how could I assure the program detected the line intersected the triangle?

enter image description here

1

There are 1 best solutions below

0
Noah Smith On

Look into the geometric objects provided in the shapely library. You can create polygons objects from those triangles and a line string object with two points. The objects have methods which check for intersection.