Calculating the area of a custom shape

M

Mac

I use the line tool to draw shapes like convex and concave polygons - what's
the best way to calculate the area of each of these? I don't want to
re-invent the wheel and I bet there are many ways... Is anybody willing to
share their insights?
 
J

John Nurick

I seem to remember this from maths at school:

1) Select a point inside the polygon.
2) Draw lines from the point to each vertex.
3) Calculate and sum the areas of the resulting triangles.

That obviously works for convex polygons and would be quite easy to
program.

But it will get more complicated for concave polygons because it's not
always easy or even possible to select a point inside the polygon from
which a line can be drawn to every vertex without crossing an edge of
the polygon. AFAIK it's still a matter of summing triangles, but some
of them will be outside the polygon and therefore have negative areas.
 
B

BTIS Jeff

I use the line tool to draw shapes like convex and concave polygons - what's
the best way to calculate the area of each of these? I don't want to
re-invent the wheel and I bet there are many ways... Is anybody willing to
share their insights?

OK - this is easy actually.
So long as the shapes do not have lines which cross you are all set.

What you want to do is to go around the polygon and calculate the area
of trapazoids from each line segment down to the X axis. You go all
the way around and while the trapazoids from line segments at the top
will have area including area totally under the polygon, the
trapazoids at the bottom will cancel this out.
So Formula for each trapzoid is : Width * Average Height
(X2-X1) * (Y2+Y1) / 2
Make sure you take absolute value at the end - this way you don't
need to worry about going clockwise vs counterclockwise around
polygon.

I hope this is helpful.


Best wishes on your project


* * Please include a copy of this message with your reply

-----

Jeff Bennett
jeff @ Bennet-Tec.Com


* Bennet-Tec Information Systems, Inc
* 50 Jericho Tpk, Jericho, NY 11753
* Phone 516 997 5596, Fax - 5597
* WWW.Bennet-Tec.Com

RELIABLE Component Software
and Custom Software Development Services

* Expert Systems * Text Processing
* Databases * Interactive Web Sites
* Diagramming, Drawing, Hotspot Graphics
* Data Input & Data Presentation Systems
* Desktop Windows, Tablets, Pocket PCs

TList(tm) / ALLText(tm) / MetaDraw(tm) / Web Signature(tm)

=================== ===================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top