This Python script generates a set of random points, computes the convex hull of those points, and calculates the minimum bounding box (OOBM) around the convex hull. The bounding box is computed by considering all possible rotations of the convex hull and selecting the smallest bounding box.
The process is visualized using matplotlib
to display the points, convex hull, and the computed minimum bounding boxes.
-
Random Point Generation: A set of random points is generated using NumPy's random number generator. The number of points is set by the variable
no_of_points
. -
Convex Hull Calculation: The convex hull of the points is calculated using the
ConvexHull
class from thescipy.spatial
module. The convex hull is the smallest convex polygon that can enclose all the points. -
Bounding Box Calculation (OOBM): The function
OOBM
calculates the minimum bounding box that can enclose the convex hull. This is done by rotating the convex hull at different angles and calculating the bounding box for each rotation. The rotation that produces the smallest bounding box is selected. -
Plotting: The points, convex hull, and minimum bounding boxes are plotted using
matplotlib
. Each bounding box is drawn as a polygon, and the convex hull is outlined with lines connecting the points that form its boundary. -
Multiple Bounding Boxes: The script will plot multiple bounding boxes (10 in this case) to show the result of different rotations.
To run this script, simply execute it in your Python environment. The script will:
- Generate a random set of points.
- Calculate the convex hull of the points.
- Compute the minimum bounding box for the convex hull.
- Plot the points, convex hull, and bounding boxes.
python convex_hull_oobm.py
The output will be a graphical plot displaying:
- The randomly generated points (represented by circles).
- The convex hull (outlined in black lines).
- The minimum bounding boxes (represented by filled polygons).
The plot will contain multiple bounding boxes (10 in total) showing the results of the bounding box rotation.