# How to calculate area percentage in GH?

Hi all,

I have 4 different layers of vectors that I created from Illustrator. My plan is to get a percentage area for each layer. The total would be all 4 of them combine.

Thanks in advance.

Peiming

Calculate the area of all shapes per layer. So you have four lists of numbers (a_0, a_1, ...)(b_0, b_1, ...)(c_0, c_1, ...)(d_0, d_1, ...)

Flatten these four lists into a single list: (a_0, a_1, ..., b_0, b_1, ..., c_0, c_1, ..., d_0, d_1, ...).

Use Mass Addition on this flat list to calculate the total area A_{total}.

Use mass addition to calculate the totals per layer. Divide one by the other and multiply by 100.

Thanks for the reply. But am I using the correct component for the total area?

You are. Whatâ€™s the error message?

It saids â€śCurve must be closed for area calculationâ€ť. So I put a closed curve on it and it shows this

The error is because the â€śClosed Curveâ€ť component is returning a boolean (true/false) value that indicates if the curve is closed or not, (not closing the curve).
But, you can easily use that, in conjunction with the â€śSiftâ€ť and â€śCombine dataâ€ť component to separate out the open curves, close them, then put the list back together. Something like this:

I followed your instruction and there is now error. But the final number(Total Area) isnâ€™t quite right. It gives me 7501, so I measure one of the big curves in rhino and it gives me half of that number.

hrmm, I didnâ€™t consider that the start and end point might not be close to each other. Can you post an example of the curves?

Thanks for looking into this. layer percentage calculation.3dm (4.7 MB) layer Percentages.gh (39.3 KB)

okay, I see what was happening. during the sifting process, the nulls were getting cleaned out, (which are needed for the combine component to know how to reassemble the list).

Iâ€™m sure there is way to maintain the nulls with strictly native components, but I was blankingâ€¦
The python component is simply getting the index of all null values, then the insert items component is using those index values to put the nulls back into the list, so the combine data component can re-assemble the list correctly.
layerPercentageCalc_NullChecks.gh (16.9 KB)

2 Likes

Boom. Thanks for providing suggestions and solutions! Just out of curious. why there is a deviation in the total value?

I guess the right way to do it is to work with VBâ€¦ I am not to skilled in VB yet

For calculating percentages use - (https://w3percentagecalculator.com/)

I had the same problem and I struggle one day. Just change the units in Rhino and make clear that your curves are closed. Often they will not close because mostly the units are to big in the standard mode.

Tolls/ Options/ Units