Untitled
unknown
plain_text
a year ago
778 B
3
Indexable
public static Point3d PolylineCentroid(ZwSoft.ZwCAD.DatabaseServices.Polyline polyline)
{
double area = 0;
double cx = 0;
double cy = 0;
int numVertices = polyline.NumberOfVertices;
for (int i = 0; i < numVertices; i++)
{
Point2d p1 = polyline.GetPoint2dAt(i);
Point2d p2 = polyline.GetPoint2dAt((i + 1) % numVertices);
// Determinante para cálculo da área e dos centroides
double determinant = (p1.X * p2.Y) - (p2.X * p1.Y);
area += determinant;
cx += (p1.X + p2.X) * determinant;
cy += (p1.Y + p2.Y) * determinant;
}
area *= 0.5;
cx = (cx / (6 * area));
cy = (cy / (6 * area));
return new Point3d(cx, cy, 0);
}Editor is loading...
Leave a Comment