Page 1 of 1
calculating area of polyline
Posted: 03 Nov 2005, 23:43
by slbarker
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,
Posted: 07 Nov 2005, 11:10
by support
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
Posted: 08 Nov 2005, 19:09
by support
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:
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>;
Sergey
please post questions to the forum or write to
support@cadsofttools.com