Author
Topic: Lwpolyline centroid (Read 5688 times)

Determine a lwpolyline centroid is a frequently asked question.Doing this, I used to create a region from the pline, get the region centroid and delete the region (using vlisp).It's not very clean, but it works (provided that the region is on XY plane of current UCS).

Recently, a guy working on an acad clone (not supporting vlisp) made me discover a routine from Reini Urban's Std Lib : GEOM-CENTROID2DThis routine works fine with plines which don't have arcs, so I tried to modify/complete it to be use with polyarcs too and to work whatever the pline OCS and elevation and whatever the current UCS.

PS : Obviously, this method seems to run more than 3 time faster than the vlisp/region one. Perhaps due to the modeler needed to create the region.

Thanks Evgeniy, Some more explainations :The algorythm (from Joseph O'Rourke ?) to get a polygon centroid is discribed hereThe very simple formula (given to me by lili2006@CADxp) to get the distance of an arc centroid from the arc center is :C^3 / 12 S (where C is the chord and S the arc area)The arc area (delimited by arc and chord) isS = R² (a - sin a) / 2 (where R is the radius and a the angle arc, a is calculated from the bulge so that if the area is signed as the bulge)

You can load all the routines in the second code window of the first message (ALGEB-AREA, TRIANGLE-CENTROID, POLYARC-CENTROID, and PLINE-CENTROID).

The pline-centroid returns polyline centroid WCS coordinates (whatever its construction plane).The polyline ename is the requested argument, so you can use it like this (none error trapping neither control on entity type) :