Discussion:
Calculate area of an enclosed irregular shape
(too old to reply)
PG
2012-01-23 22:11:03 UTC
Permalink
Hi,

I have a series of approx. 40 points (x,y) that make up an irregular
shape.

Is there a simple library / function that I can call that will
calculate the enclosed area of this shape?

TIA.

PG
Jamie
2012-01-23 23:21:10 UTC
Permalink
Post by PG
Hi,
I have a series of approx. 40 points (x,y) that make up an irregular
shape.
Is there a simple library / function that I can call that will
calculate the enclosed area of this shape?
TIA.
PG
there is a simple process for that.
Var
Xl,XH, YL, YH, W, H:integer;
PS:Array of TPoints;
R:Trect;
Begin
// Initialize the limits to what ever first.
PS := From where ever these are and assume a 0 base array.
XL := PS[0].X; YL := PS[0].Y; // start with first set.

For L := 1 to NumberOfPoints-1 do
Begin
If (PS.X < XL Then XL := PS.X;
If (PS.X > XH THen XH := PS.X;
If (PS.Y < YL Then YL := PS.Y;
If (PS.Y > YH Then YH := PS.Y;
End;
// Get Size of square;
W := XH-XL+1;
H := YH-YL+1;

// Get a rectangle of the area.

R.Left := XL;
R.Top := YL;
R.Right:= XH;
R.Bottom:= YH;


That should about cover it.



I did this from memory so there maybe some errors here but you should
get the idea.


Jamie
Dr J R Stockton
2012-01-24 18:53:00 UTC
Permalink
In comp.lang.pascal.delphi.misc message <a306d243-b288-4b1d-a5a0-6b214de
Post by PG
Hi,
I have a series of approx. 40 points (x,y) that make up an irregular
shape.
Is there a simple library / function that I can call that will
calculate the enclosed area of this shape?
If you can pick one point within or on the edge of the area from which
the points appear everywhere concave (approximate example, the Isle of
Wight - Newport, but not Yarmouth or either side of Cowes), then you can
draw imaginary lines from that point to each of the 40 (or 39),
splitting it up into triangles. The area of a triangle is easy enough,
for example by Root s s-a s-b s-c, and you can add them all together.

Everywhere concave is in fact too strong; the need is to be able to see
all of the inside of the border from the point. Otherwise, there will
have to be subtractions.

There will probably be a better way, and that probably does not matter.

Google for area of a many-point irregular polygon soon finds
http://en.wikipedia.org/wiki/Polygon which gives sufficient answers for
most cases.
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
<http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
Jim Higgins
2012-01-25 19:42:01 UTC
Permalink
Post by PG
Hi,
I have a series of approx. 40 points (x,y) that make up an irregular
shape.
Is there a simple library / function that I can call that will
calculate the enclosed area of this shape?
I don't know of a library, but you can use an algorithm to calculate
the area. I think it's called Bragg's algorithm. Maybe not.


Assuming you can describe the polygon as a series of vertices in a
rectangular coordinate system with vertices at (x1, y1), (x2, y2),
..., (xn, yn), the area may be calculated as:

A = (x1y2 + x2y3 + x3y4 + ··· + xny1) - (x2y1 + x3y2 + x4y3 + ··· +
x1yn) ÷ 2

The vertices are labeled x1y1, x2y2, etc., starting anywhere on the
polygon and proceeding counterclockwise.

Loading...