Center of a polyline

Sorry but yet another thing that’s bugging me and that I can’t figure out.
The developers kit lists this method for polylines:
CenterPoint Compute the center point of the polyline as the weighted average of all segments.

Here is a polyline set at the origin (the center is a point placed at the center Osnap):
Poly1

Here is the excel calculation for the 8 line segments:
Poly2

So why does Rhino show (2, 2.25) for the centre and excel has (2.11, 2.39)?

SteveOh

Hello - can you please post the curve? (I believe Cen osnap averages the vertices on the polyline - see what AreaCentroid gets you.

Yeah… confirmed, at least for Cen Osnap, not sure of the function you are using.

Polyline.CenterPoint() is more accurate than Cen osnap but still doing some averaging and not calculating the area centroid.

    mp=Rhino.Geometry.AreaMassProperties.Compute(pLineCrv, .001)
    cenPt = mp.Centroid

-Pascal

Pascal,

Thanks for clearing that up. I thought the picture of the curve was in the post but here it is again.

image001.png

Since the method indicated a “weighted average of all segments”, I was multiplying the segment length by the x and y positions of the segment centres. Summing
them up and dividing by the polyline length. I’ll have to think about how/why/when I might use the average of the segment endpoints. But at least I now know what the calculation is doing!!

SteveP

Sorry, bigger brains, I did not notice this was on ‘Rhino Developer’, I thought it was on Rhino. I’ll butt out…

-Pascal