How to Find Area and Perimeter of a Closed LWPolygon
Posted: 07 Aug 2022, 00:20
hello
How to Find Area and Perimeter of a Closed LWPolygon in cadpicturebox?
How to Find Area and Perimeter of a Closed LWPolygon in cadpicturebox?
CADSoftTools - AutoCAD DWG DXF HPGL (PLT) SVG CGM STEP IGES STL SAT viewers, converters and developer tools. Delphi and C# source code.
https://cadsofttools.com/forum/
Hello,
Code: Select all
double distance_between_points = DPoint.Distance(point1, point2);
Code: Select all
CADLWPolyLine vLWPolyline = new CADLWPolyLine();
CADEntityCollection vertices = vLWPolyline.Vertexes;
Masoud wrote: ↑08 Aug 2022, 11:16Thank you Catherine
I wrote this function and put it in the form so that others can use it
public class Point3D
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
public Point3D()
{
this.X = 0;
this.Y = 0;
this.Z = 0;
}
}
private double CalculateAreaPolygon(List<Point3D> Points)
{
double Sum1 = 0;
double Sum2 = 0;
for (int i = 0; i < Points.Count; i++)
{
if (i < Points.Count - 1)
{
Sum1 = Sum1 + (Points.X * Points[i + 1].Y);
}
else
{
Sum1 = Sum1 + (Points.X * Points[0].Y);
}
}
for (int i = 0; i < Points.Count; i++)
{
if (i < Points.Count - 1)
{
Sum2 = Sum2 + (Points.Y * Points[i + 1].X);
}
else
{
Sum2 = Sum2 + (Points.Y * Points[0].X);
}
}
return (Sum1 - Sum2) / 2;
}
Thanks for making my day. If I face any problem, I will message you.support wrote: ↑08 Aug 2022, 10:42Hello,
CAD .NET doesn't have ready-to-use Area and Perimeter functions. However, you can implement them yourself. For example, you could use ready-to-use api DPoint.Distanceto get the distance between points and then calculate the sum of all the distances to get the perimeter of the closed LW Polyline.Code: Select all
double distance_between_points = DPoint.Distance(point1, point2);
As for the Area. You can calculate the area of a closed LW Polyline by using polygon area formulas (e.g. https://en.wikipedia.org/wiki/Shoelace_formula). To get information about vertexes, please, useBest regards,Code: Select all
CADLWPolyLine vLWPolyline = new CADLWPolyLine(); CADEntityCollection vertices = vLWPolyline.Vertexes;
Catherine.