# Centroid for line or polyline

Was wondering if a line or polyline or curve have its centroid turned on like objects can?

What objects have their centroid turned on? There are also different definitions of what is actually the â€ścentroidâ€ť of an object - it could be the center of its bounding box; or if it is a surface or volume object, it could also be the surface or volume centroid. The three are likely to be different.

â€“Mitch

A line or curve can have a centroid just as a surface of volume has a centroid. Unfortunately Rhino does not appear to have a native tool for determining the centroid of a line or curve similar to AreaCentroid or VolumeCentroid.

One workaround to get close, but not â€śexactlyâ€ť the centroid of a line or curve is to create a pipe around the line or curve with constant diameter â€śsmallâ€ť compared to the length of the line curve and flat caps. Then use VolumeCentroid to find the centroid of the pipe. The smaller the diameter of the pipe the more accurate the result will be up to a point. Try 1/100 or 1/1000 the length of the line or curve as an initial diameter and experiment.

OK, this is the first time I have heard of someone asking for a curve centroid, which is why I thought it was strange.

As far as I can tell a lineâ€™s centroid will just be its midpoint (thus object-snappable).

For arbitrary open curves, it seems that it might be as simple as the average of a (theoretically infinite) number of points sampled along the curve. In that case, I imagine that a good approximation could be relatively easily scripted, either using a predetermined sample density along the curve (relative to file tolerance) or trying to iterate through increasing sampling counts until the difference between successive calculations flattens out to stay within a given toleranceâ€¦ I might even be able to write something like that myself, but @dale this might be a good candidate for a new commandâ€¦

â€“Mitch

The centroid of a straight line is the center, similar to the centroid of a rectangle, disc or ellipsoid is the center, and the centroid of a rectilinear â€śbrickâ€ť, sphere or ellipsoid is the center.

Rhino already has algorithms for calculating the centroid of a solid which involves an integral over a volume, and of a surface which involves an integral over a surface. So in principal it would be a simple task for someone with access to the source code of those algorithms to simplify them to an integral over a curve.

I experimented with using the pipe method with a curve 100 units long and decreasing pipe diameters. Going from a diameter of 1 to a diameter of 0.1 resulted in a noticeable shift in the centroid location. A diameter of 0.01 resulted in a very small (less than 0.01) shift. I then tried a diameter of 0.001 and the centroid jumped to a new location. This appeared to be independent of the absolute accuracy set in properties, and may reflect something going on with the pipe model.

For a steel member section, such as a rectangular hollow section. Is it possible to create a centerline of a segment?
Thanks

I think intuitionusa is talking about the equivalent function of â€śmasspropâ€ť in Autocad.

Not automatically, no. You start the `line` command, for start point type `between` and `end-snap` to opposing corners of the inner wall. In the example that you posted in another thread, start the `line` command and activate the `vertical` option so that you can just snap to any point on the far end of the section.

Thanks!
Could you do me one more favor, telling me how to slice/trim the RHS extrusion by a circle plane (Autocad - Slice) as attached.slice.3dm (35.6 KB)

@davidcockey

Below is a quick script hack for a curve centroid. Itâ€™s a bit slow because of the iterations requiredâ€¦

â€“Mitch

CurveCentroid.py (2.0 KB)

@Helvetosaur

Here is an improved but still simple algorithm for the basic calculation using trapezoidal rule for integration. It is applicable for both open and closed curves.

• Divide curve into n segments

• Average the x, y and z coordinates of the points

• If the curve is open subtract 1/2 of the first and last point coordinates divided by n

This should converge faster for open curves than the simple average of the point coordinates.

Two different centroids related to a closed planar curve:

1. The centroid of the curve itself. All curves have a centroid, whether open or closed, planar or not planar.

2. The centroid of the area enclosed by the closed planar curve.

The Rhino command AreaCentroid calculates the second.

Trim if you want to discard one side. Split if you want to keep both sides.

[quote=â€śyoungken, post:7, topic:26547, full:trueâ€ť]
I think intuitionusa is talking about the equivalent function of â€śmasspropâ€ť in Autocad.
[/quote]Rhino has mass property commands for both surfaces and volume: Area, AreaCentroid, AreaMoments, Volume, VolumeCentroid and VolumeMoments. The â€śAreaâ€ť commands work for the area enclosed by a planar closed curve as well as both planar and non-planar surfaces.

[quote=â€śyoungken, post:6, topic:26547, full:trueâ€ť]
For a steel member section, such as a rectangular hollow section. Is it possible to create a centerline of a segment?Thanks
[/quote]Do you want the principal axis for the section area? If so those can be calculated using the results of the Area, AreaCentroid and AreaMoments commands. Someone may have a script which does the calculations.

OK, thanks (Iâ€™m not a math person). I donâ€™t quite get that partâ€¦

Subtract 1/2 of the first and last point coordinates divided by nâ€¦

Subtract from what ? From each previous sample, then average again and loop?

Thanks, --Mitch

@Helvetosaur

â€˘ Divide curve into n segments

â€˘ Average the x, y and z coordinates of the points

â€˘ If the curve is open subtract 1/2 of the first and last point coordinates divided by n from the averages

These are the calculation steps for the centroid based on n segements.

Thanks for all of the responses! I hail from FormZ as that used to be my main modeling tool. Having Centroid for lines and curves was very useful because it gave you a handle to grab the line or curve. If I had multiple curves or parts of a curve atop of another curve it allows you to keep track of them better. Centroid is great on just a straight line because it gave me a reference that I could use when modeling. I will check out the script Helvetosaur.

The centroid of a line is just its midpoint as stated previously. If you LMB click somewhere near the midpoint of a line (with the osnap mid enabled as persistent), it will snap to the midpoint of the line (you will see the osnap light up) and you then can drag it to another snap point (commonly called snap-dragging). Otherwise with the normal move/rotate commands etc. you can always grab the midpoint via the osnap as well. No need for scripts.

Note also that the centroid (as davidcockey is describing it) will likely not lie on the curve if the curve is anything but a straight lineâ€¦

â€“Mitch

Just getting back to this - so if i understood correctly:

letâ€™s say my n is currently 1000.

• I have a 1000 division points, that I average into a point X,Y,Z
that is â€ścloseâ€ť to the centroid.

• I get pt[0] and pt[n] and add them together, divide by n to get
another x,y,z point

• I subtract half of that from the average, which gets me whatâ€¦
closer?

• I then iterate, say doubling n, do the above and compare? The
difference should converge faster?

â€“Mitch

@Helvetosaur

Almost correct.

The subtraction is only done for open curves, not for closed curves. Also n is the number of segments the curve is divided into. An open curve divided into n segments will have n+1 points; a closed curve will have n points.

The subtraction improves the accuracy of the estimate with n segments. It should converge faster.