Help!!!! how to create find the area of a polygon from a list of coord


can anybody help me with code to open and read a comma delimited text file containing x,y coordinates:

parse each line, and load the x and y coordinates into two one dimensional arrays

then take these arrays and calculate the area of the polygon

if anybody can help me with this code it would greatly appreciated


  • Try This Code
    It Only Works For Four Sides
    if u want to give input for more or less than 4 sides then u mat be able to change it
    Public Sub CalculateArea()
    ' I Will Just Input the Points NOT THE ID
    ' Area of Four Sided PolyGon is
    '= (1/2)(x1*y2 - x2*y1 + x2*y3 - x3*y2 + x3y4 - x4y3 + x4*y1 -x1*y4)
    'And Five Sided Is=
    'A = (1/2)(x1*y2 - x2*y1 + x2*y3 - x3*y2 + x3y4 - x4y3 + x4*y5 -
    'x5*y4 + x5*y1 - x1*y5)

    Dim Point1(2) As String
    Dim Point2(2) As String
    Dim Point3(2) As String
    Dim Point4(2) As String
    Dim p1(2) As Double
    Dim p2(2) As Double
    Dim p3(2) As Double
    Dim p4(2) As Double
    Point1 = TextBox1.Text.Split(",")
    Point2 = TextBox2.Text.Split(",")
    Point3 = TextBox3.Text.Split(",")
    Point4 = TextBox4.Text.Split(",")
    Dim i As Integer = 0
    While i <> Point1.Length
    p1(i) = GetDouble(Point1(i))
    p2(i) = GetDouble(Point2(i))
    p3(i) = GetDouble(Point3(i))
    p4(i) = GetDouble(Point4(i))
    i += 1
    End While
    'So far We have got the Points
    'For Example X1,Y1 = p1(0),p1(1)
    'Or u Can say
    'xN,yN = pN(0), pN(1)
    '(1/2)(x1*y2 - x2*y1 + x2*y3 - x3*y2 + x3y4 - x4y3 + x4*y1 -x1*y4)

    Dim x1y2 As Double = p1(0) * p2(1)
    Dim x2y1 As Double = p2(0) * p1(1)
    Dim x2y3 As Double = p2(0) * p3(1)
    Dim x3y2 As Double = p3(0) * p2(1)
    Dim x3y4 As Double = p3(0) * p4(1)
    Dim x4y3 As Double = p4(0) * p3(1)
    Dim x4y1 As Double = p4(0) * p1(1)
    Dim x1y4 As Double = p1(0) * p4(1)

    Dim area As Double = 0.5 * (x1y2 - x2y1 + x2y3 - x3y2 + x3y4 - x4y3 + x4y1 - x1y4)
    MsgBox("The Area of Four Sided Polygon is = " & area.ToString())
    End Sub
    Public Function GetDouble(ByVal str As String) As Double
    Return System.Convert.ToDouble(str)
    Catch ex As Exception

    End Try
    its a bit tedious but i hope u understand it

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion