I want to calculate the area of a polygon with empty space

The picture is strange, but the red circles are vertices, the blue lines are lines or linesegments, the gray is empty space, and the green is the filled space to be calculated.

How do I calculate this if the vertex information is contained in an array that contains only lines or linesegments?

I’d use the shoelace formula.

1 Like

KakaoTalk_20240727_190803397

Is it possible to respond in this case as well?

1 Like

No. The shoelace formula works on non-selfintersecting polygons.

2 Likes

Area of big polygon minus area of empty polygons.

1 Like

Is it better to analyze and classify data? Or is there a separate algorithm that can be used in most situations?

I think you do not want self-intersecting polygons. If you have such, you’d better split them, otherwise you will run in a lot of problems, like 90% of the algorithms will fail.

As for the shoelace algorithm, it is already implemented in Three.js – get the coordinates as 2D vectors, push them in an array and use ShapeUtils.area. Because the shooelace algorithm calculates signed area, you must take the absolute value of the result. Do the same with the holes and subtract their area from the overall area.

3 Likes