calculating area of polyline

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: SDS, support, admin

Post Reply
slbarker
Posts: 12
Joined: 03 Nov 2005, 23:39
Location: New Zealand

calculating area of polyline

Post by slbarker » 03 Nov 2005, 23:43

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,

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 07 Nov 2005, 11:10

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

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 08 Nov 2005, 19:09

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

Post Reply