0

I have coordinates of polygon bounding box, first bracket is the x coordinates, second is the y coordinates.

(148.41213249755577, 156.62462117931182, 161.0770759875118, 169.21802106108976, 171.53578439669775, 177.31429522801588, 171.7025899944188, 165.89430263865654, 164.03709560714134, 155.85755768504498, 152.3381684145277, 144.09367135708533, 148.41213249755577) 
(212.51320231696795, 212.9654197878803, 211.25215507829296, 211.70582096911937, 211.83498166961178, 212.15699750932652, 223.56562737602863, 223.26504232165132, 222.18842269217154, 221.7624098796552, 221.57911041509468, 221.1497143523005, 212.51320231696795)

How can I compute area of that bounding box?

With rectangle is okay: (box[2] - box[0]) * (box[3] - box[1]) but for polygon I don't know. :/

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Leon
  • 33
  • 7
  • A bounding box is by (the most common) definition a rectangle so you already know how. So is the problem that you need to find the bounding box? – GuillemB Jul 04 '22 at 10:30
  • I need to find area of polygon bounding box. I have coordinates but don't know how to find area, not for rectangle. – Leon Jul 04 '22 at 10:33
  • If I understand correctly you need to find the area of the polygon. Most people understand that the bounding box of a polygon is the smallest rectangle that contains a set of points. – GuillemB Jul 04 '22 at 10:35
  • If that is the case then you might find helpful the following answer: https://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates – GuillemB Jul 04 '22 at 10:38
  • Hmm, yea that makes sense. So I need to make a loop through all small rectangles in one big polygon bounding box and compute the formula what I wrote up ? Okay thank you – Leon Jul 04 '22 at 10:40
  • @Leon you still seem to be confusing bounding box with area. Maybe provide an image marking what is the thing you want to calculate – matszwecja Jul 04 '22 at 10:43
  • @Leon There are libraries available to you linked on my comment above that will allow you to calculate the area of a polygon easily and efficiently. – GuillemB Jul 04 '22 at 10:46

1 Answers1

0

Coupling together the coordinates to get a point with zip. Use min, max with a callback to specify the coordinate wrt apply the selection.

X = (148.41213249755577, 156.62462117931182, 161.0770759875118, 169.21802106108976, 171.53578439669775, 177.31429522801588, 171.7025899944188, 165.89430263865654, 164.03709560714134, 155.85755768504498, 152.3381684145277, 144.09367135708533, 148.41213249755577)
Y = (212.51320231696795, 212.9654197878803, 211.25215507829296, 211.70582096911937, 211.83498166961178, 212.15699750932652, 223.56562737602863, 223.26504232165132, 222.18842269217154, 221.7624098796552, 221.57911041509468, 221.1497143523005, 212.51320231696795)

points = tuple(zip(X, Y))

# boundaries of the bounding box
left, right = min(points, key=lambda p: p[0]), max(points, key=lambda p: p[0])
bottom, top = min(points, key=lambda p: p[1]), max(points, key=lambda p: p[1])

# area
base = right[0] - left[0]
height = top[1] - bottom[1]

A = base * height
print(A)
#409.06123174819976
cards
  • 3,936
  • 1
  • 7
  • 25