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.
I appreciate any and ALL assistance.
-Iain
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.
Any suggestions? On how to make the above work, or a better way?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
I appreciate any and ALL assistance.
-Iain