calculating area of polyline
Moderators: SDS, support, admin
calculating area of polyline
There doesn't seem to be a property or method to show the area of a closed polyline.
Does anyone have any code to do this?
thanks,
Does anyone have any code to do this?
thanks,
Hello,
It is necessary to use a mathematical algorithm. We shall try to find it and to implement it in our demo. So you will be able to use it.
Sergey.
please post questions to the forum or write to support@cadsofttools.com
It is necessary to use a mathematical algorithm. We shall try to find it and to implement it in our demo. So you will be able to use it.
Sergey.
please post questions to the forum or write to support@cadsofttools.com
Hello!
The following code can be implemented with CADImportVCL (available on: http://www.cadsofttools.com/download/CADImportVCL.zip). It allows counting of the area inside of closed polyline.
Delphi code:
Sergey
please post questions to the forum or write to support@cadsofttools.com
The following code can be implemented with CADImportVCL (available on: http://www.cadsofttools.com/download/CADImportVCL.zip). It allows counting of the area inside of closed polyline.
Delphi code:
Code: Select all
<b>function</b> GetArea(APolygon: TsgDXFPolyline): Double;
<b>var</b>
I, Cnt, J: Integer;
Pt: <b>array</b> [0 .. 1] <b>of</b> PFPoint;
<b>begin</b>
Result := 0.0;
Cnt := APolygon.PolyPoints.Count;
<b>if</b> Cnt >= 3 <b>then</b>
<b>begin</b>
J := 1;
Pt[J] := PFPoint(APolygon.PolyPoints.Items[Cnt - 1]);
<b>for</b> I := 0 <b>to</b> Cnt - 1 <b>do
begin</b>
J := J <b>xor</b> 1;
Pt[J] := PFPoint(APolygon.PolyPoints.Items[I mod Cnt]);
Result := Result + (Pt[J]^.X + Pt[J <b>xor</b> 1]^.X) * (Pt[J]^.Y - Pt[J <b>xor</b> 1]^.Y);
<b>end</b>;
Result := Abs(Result) * 0.5;
<b>end</b>;
<b>end</b>;
please post questions to the forum or write to support@cadsofttools.com