Irregular Polygon Area

icb12

New Member
Joined
Sep 15, 2009
Messages
9
I have a need to calculate the area of an irregular polygon.
Using the area by coordinates method. Given that you have the x,y coordinates of every vertice.

The equation is as follows..
A=(1/2)[{(x1*y2)+(x2*y3)+(x3*y4)...(xN*y1)} - {(y1*x2)+(y2*x3)+(y3*x4)...(yN*x1)}]

Assuming the vertice coordinates are (x1,y1), (x2,y2),...(xN,YN)- listed in separate columns on sheet1

This is simple enough to do in excel when the polygon has just a few vertices.
But when the closed traverse (polygon) is huge with tons of vertices the equation becomes convoluted and a PITA.

I'd like to write a function in VB that would allow me to quickly and easily compute the area simply by selecting the coordinates I have entered on the sheet1.

This was suggested to me by someone more skilled than I... but I can't seem to make it work.
Public Function getArea(ByVal a As ListBox, ByVal b As ListBox)

' Make sure to add the first element to the end to close the polygon
a.Items.Add (a.Items(0))
b.Items.Add (b.Items(0))

Dim n, area, i
n = a.Items.Count

i = 0
area = 0

Do
area = (a.Items.Item(i) * b.Items.Item(i + 1) - a.Items.Item(i + 1) * b.Items.Item(i))

i = i + 1
Loop While i < n - 1

area = Math.Abs(area * 0.5)

' if you have a certain scale you can use this, or skip it
area = applyScale((9 / 64), area)

Return area
End Function
Any suggestions? On how to make the above work, or a better way?

I appreciate any and ALL assistance.

-Iain
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Thanks a lot for this but I need this X, Y table to be automatically filled for me. I will click on different cells on the sheet just randomly and excel will record these cell addresses (coordinates) one by one in order. first click coordinates are tables first row, second click is second and so on. how is it possible? thanks in advance.


Hi

An easy way to calculate the area of the polygon is to close it (adding again the first vertice at the end).

In this case, the vertices of the polygon are in rows 2:6. As you can see I added the first vertice again at the end.

The area, in E2:

=1/2*ABS(SUMPRODUCT(A2:A6,B3:B7)-SUMPRODUCT(B2:B6,A3:A7))


ABCDEF
1XY
212Area7
325
436
545
654
712
8
[Book2]Sheet1

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,325
Messages
6,124,252
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top