简体   繁体   中英

Finding minimum bounding box for a set of points

Im trying to find the minimum bounding box for a set of points. I used the library https://bitbucket.org/william_rusnack/minimumboundingbox/src/master/

I want to enclose these coordinates in the minimum bounding box:-

#INPUT COORDINATES
    ('297.153338872911', '373.3796368193535')
    ('222.75', '278.7499999999999')
    ('222.75', '278.7499999999999')
    ('42.25', '251.75')
    ('179.25', '390.5')
    ('298.403338872911', '373.3796368193535')
    ('0.6400000000000537', '240.0000000000201')
    ('75.26400000000632', '390.9120000000328')


 # OUTPUT BOUNDING BOX COORDINATES , PLOTTED 
[(-22.685403520024096, 373.8408037637353),
 (0.6400000000000432, 240.0),
 (288.84381342985046, 428.133250381587),
 (312.16921694987457, 294.2924466178517)]

在此处输入图像描述

But as you can see from the output itself the bounding box is coming out as tilted/inclined. That's all right, but what I want is for the bounding box to be straight to the horizontal & vertical plane of my desktop. How can I achieve this without losing the bounding box functionality (ie any point popping out of the bounding box while making it straight)?

I tried this code also , but it rotates the rectangle and finds the best possible bounding box which mostly would be inclined rectangle. But I strictly want a straight rectangle.

For sake of notation, let's assume that your points are a list of pairs (2-tuples), each pair being the x,y coordinates of a point.

point_list = [(10,12), (11,14), (15,20), ...]

Your orthogonal bounding box has simply x and y limits: the min and max of each coordinate:

x_min = min(point[0] for point in point_list)
x_max = max(point[0] for point in point_list)
y_min = min(point[1] for point in point_list)
y_max = max(point[1] for point in point_list)

Your bounding box is the four edges defined by those min/max values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM