I have the following code and need to know what the method is for getting the area of a closed, planar curve inside a block in order to record it as User Data.

```
Rhino.DocObjects.ObjRef objref;
var rc = Rhino.Input.RhinoGet.GetOneObject("Select instance", false, Rhino.DocObjects.ObjectType.InstanceReference, out objref);
if (rc != Rhino.Commands.Result.Success)
return rc;
var iref = objref.Object() as Rhino.DocObjects.InstanceObject;
if (iref != null)
{
var idef = iref.InstanceDefinition;
if (idef != null)
{
var rhino_objects = idef.GetObjects();
for (int i = 0; i < rhino_objects.Length; i++)
if ((rhino_objects[i].Geometry).ObjectType == Rhino.DocObjects.ObjectType.Curve)
{
if ((((Rhino.DocObjects.CurveObject)(rhino_objects[i])).CurveGeometry).IsClosed)
{
if (rhino_objects[i].Attributes.LayerIndex == LayerIndexOf("Cut"))
{
if (((Rhino.Geometry.PolyCurve)(rhino_objects[i].Geometry)).IsPlanar())
{
//What method to I place here to get the area of this closed curve? <----- my question.
}
}
}
}
}
}
return Rhino.Commands.Result.Success;
}
```

Hi @cestes001,

You need to use the area mass properties class (the following is in Python! sorry ;)):

```
curveToTest = this closed curve
areaMassProps = Rhino.Geometry.AreaMassProperties.Compute(curveToTest)
curveArea = areaMassProps.Area
```

GM

New problem. The Rhino.Geometry.AreaMassProperties class reports values for the x, y and z components of the centroid of the area property of a planar, closed curve, however I can find no direct relationship between these values and those reported by the AreaCentroid command in Rhino.

To verify this, I created a square planar curve centered at 0,0 and took the values from the Rhino.Geometry.AreaMassProperties class. They were reasonable and reported an accurate area with a centroid at 0,0,0 (approximately). However, when I moved the curve down one unit and left one unit, the values for x, y, and z were the same as before (approximately.

These same values for an actual planar, closed curve not near 0,0,0 vary widely from the ones reported when I use the AreaCentroid command.

Any thoughts?

I can’t replicate your results.

The following are the results of applying the same process you did:

```
Square curve (50x50mm), centred at 0,0,0
AreaMassProperties results:
Area: 2500.0
Centroid: 1.45519152283669E-15,-2.18278728425503E-15,0
Rhino command results:
Area: Area = 2500 (+/- 1e-06) square millimeters
Centroid: -3.08324794e-15,-9.86639342e-16,0 (+/- 1e-24,1.5e-15,0)
(move curve to (-1,-1,0))
AreaMassProperties results:
Area: 2500.0
Centroid: -0.999999999999999,-1,0
Rhino command results:
Area: Area = 2500 (+/- 1e-06) square millimeters
Centroid: -1,-1,0 (+/- 1e-09,1e-09,0)
```

As you can see from the above results, the error is negligible in both cases.

If you report AreaMassProperties.CentroidError along with your results, you’ll see that it varies slightly from what seems to be a hardcoded and constant error threshold from the AreaCentroid command.

Perhaps it has something to do with the relationship between your document tolerance settings and the units you are working in. Not sure.

Perhaps @pascal can shed some expert light on this?

GM

I think I’ve figured out why. The coordinates I’m getting are of the centroid of a closed curve within a block. Accordingly, no matter where I place the block, the coordinates of that centroid will be the same.

What is needed is a means of transforming the centroid’s coordinates to world coordinates.

Ah, you did not mention the curve was inside a block!

In that case, I imagine you would extract the block’s transformation and apply it to the coordinates of the centroid.

GM