@r_gigante
Thanks for the response. The shoelace formula was new to me and it was interesting after reading some explanation.
Unfortunately, for some reason it breaks.
It works with a 4 point plane, but not with a 16-point plane.
Here is the revised code I used
import c4d
x = []
y = []
def main():
baseVector = op.GetAllPoints()
for vector in baseVector:
x.append(vector[0])
y.append(vector[1])
def polygonArea(X, Y, n):
# Initialze area
area = 0.0
# Calculate value of shoelace formula
j = n - 1
for i in range(0,n):
area += (X[j] + X[i]) * (Y[j] - Y[i])
j = i # j is previous vertex to i
# Return absolute ;
return int(abs(area / 2.0))
if __name__=='__main__':
main()
print polygonArea(x, y, 16)
You can also check the 4 point and 16 point plane here:
https://www.dropbox.com/s/6qfhy9yw3l3xdil/c4d081_area_irregular_shape.c4d?dl=0
The area (since this is a square) should result to 160,000 cm2
Thank you for looking at the problem.