How to determine if a point is inside a 2D convex polygon?

This page: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html shows how to do this for any polygon. I have a Java implementation of this, but it is too big to post here in its entirety. However, you should be able to work it out: class Boundary { private final Point[] points; // Points making up the boundary … /** * Return … Read more

Checking if a point is inside a polygon

I would suggest using the Path class from matplotlib import matplotlib.path as mplPath import numpy as np poly = [190, 50, 500, 310] bbPath = mplPath.Path(np.array([[poly[0], poly[1]], [poly[1], poly[2]], [poly[2], poly[3]], [poly[3], poly[0]]])) bbPath.contains_point((200, 100)) (There is also a contains_points function if you want to test for multiple points)

Calculate overlapped area between two rectangles

This type of intersection is easily done by the “min of the maxes” and “max of the mins” idea. To write it out one needs a specific notion for the rectangle, and, just to make things clear I’ll use a namedtuple: from collections import namedtuple Rectangle = namedtuple(‘Rectangle’, ‘xmin ymin xmax ymax’) ra = Rectangle(3., … Read more