Area of closed polyline

What do closed polylines have to be converted to in order to measure their area? This doesn’t seem to be a problem in Grasshopper, but somehow it seems to be with Rhino.Common. Is it necessary to first fit a curve through the polyline?

are you looking for the area or the area centroid? for any area calculation you need a planar polyline or a surface.

If you’re looking for the areacentroid, you can bbox the polyline and get the bboxes center or areacentroid

best –


I am looking just for the area value. I meant that AreaMassProperties cannot be used on a polyline.

it can only be used on a planar (flat in any sense) polyline.

if it is not planar, you can patch (command _patch) the polyline to get a approximate surface and get the surfaces area.

it’s a math issue. you cant have a area from just lines. a planar curve or polyline can be transfered to a trimmed surface which can have a area. a surface from a non planar polyline has always a deviation and therefor is not automated.

you need to do it in two steps: patch then area.

Why not just do this:

import rhinoscriptsyntax as rs

object = rs.GetObject("Select the closed polyline")
if object: print(rs.Area(object))

One can also triangulate the polyline and compute the area of the resulting triangles:

did you try with a no planar polyline?

from my point of view its the same function whether you call the function by python, c#, grasshopper or rhino.

but maybe I’m wrong


Maybe I am missing something very basic. (6.4 KB)
Here are two planar objects. One is a polyline, the other a curve. The same script works on one and not the other.
var tmp = Rhino.Geometry.AreaMassProperties.Compute(x, .001);
A = tmp.Area;

set the c# element to Curve instead of polyline and it works fine

Ok, so I suppose this way it changes the type to curve automatically?
But if I obtain the polyline inside the script (e.g. from intersecting a plane and a mesh), how would I have to change the type? I know that the polylines are planar, but the function doesn’t seem to work on them directly.


no, it doesn’t work directly as massproperties expects a curve as input, which has another structure than polyline.

Thank you, that’s it!

1 Like

No, just on planar closed polylines. I didn’t see any mention of non-planar in the original post.

@DanBayn Thanks for the answer, I was looking for the Rhino.Common method though.

yep, I’m sorry, I initially missunderstood the question…
my bad

Here’s a quick implementation of the logic I described: (5.8 KB)

Hey Anders, great to see other geeks:)

cool! thanks, although it wasn’t for me, my answer was for Dan Bayn and just because I missunderstood the initial question in the first place, haha;)

I admit being more fluid in c# than py, but if I understand correctly, you ‘subdivide’ the polyline by mesh triangles that by their nature are planar, then use the proper math method instead of the existing function and add up the areas. right?

It’s indeed more precise than patch as it follows exactly the polyline, but why would you reprogram the area function for mesh triangles? performance?

Ah yes, sorry. Might have browsed through the thread a bit too fast :wink:

I’m skipping the meshing step here, and just operating directly on the polyline vertices using the indices provided by the TriangulateClosedPolyline method (which does actually implement/return the MeshFace structure though).

I might be wrong, but the mesh class doesn’t provide any properties/methods that return/compute area. So this function is just a way around that. I would expect operating on meshes and using basic math would indeed be faster than going down the NURBS with AreaMassProperties route.

you are right, I thought the meshface structure did have area, but it doesn’t. Just for meshes you can have massareaprop. I guess there’s a workaround like you did in the grasshopper element, as you can plug a single meshface into the area element.
And finally just for the reason that the gh element does a couple of checks what has been plugged in, your method is surely faster.

And faster than patch and area. nice job!

Thanks a lot for this exchange, it’s highly appreciated!!


1 Like