I have a irregular 2D polygon, it is a PackedVector2Array
, how do I get its area?
1 Answer
\$\begingroup\$
\$\endgroup\$
You can use Gauss' shoelace formula:
func calculate_area(mesh_vertices: PackedVector2Array) -> float:
var result := 0.0
var num_vertices := mesh_vertices.size()
for q in range(num_vertices):
var p = (q - 1 + num_vertices) % num_vertices
result += mesh_vertices[q].cross(mesh_vertices[p])
return abs(result) * 0.5