I have a 2D vision cone and I want to check if a rectangle intersects it. How can I do this? Like in this picture the cone and the rectangle intersect:

I have a 2D vision cone and I want to check if a rectangle intersects it. How can I do this? Like in this picture the cone and the rectangle intersect:

I would like to provide an answer using the shapely Python library.
Import relevant libraries:
import matplotlib.pyplot as plt
from shapely.geometry import Polygon, Point, LineString, MultiLineString
Create the rectangle (you will have to modify its vertex coordinates):
rectangle = Polygon([(0.5, 0), (4, 0), (4, 2), (0.5, 2)])
Create the circular sector (you will have to modify its aperture angle and position):
# Create a circle whose radius is given by the buffer argument.
circle = Point(0, 0).buffer(1.0)
# Create two lines to cut the circle into a sector.
a = LineString([(0, 0), (1, 1)])
b = LineString([(0, 0), (1, -1)])
multi_line = MultiLineString([a, b])
line_poly = multi_line.convex_hull
# Intersect the two lines with the circle
circular_sector = circle.intersection(line_poly)
Let's have a look at the rectangle and circular sector:
plt.plot(*circular_sector.exterior.xy)
plt.plot(*rectangle.exterior.xy)
plt.gca().set_aspect('equal', adjustable='box')
Check if the two shapes intersect with each other:
>>> print(circular_sector.intersects(rectangle))
True
The result is True.
Let's examine other cases (for the sake of simplicity I am going to modify the rectangle only):
No intersection
rectangle = Polygon([(1.5, 0), (4, 0), (4, 2), (1.5, 2)])
>>> print(circular_sector.intersects(rectangle))
False
Whole rectangle inside the sector
rectangle = Polygon([(0.2, 0.0), (0.5, 0.0), (0.5, 0.1), (0.2, 0.1)])
>>> print(circular_sector.intersects(rectangle))
True