I am trying to read the description of a polygon from a file and compute the area of the polygon according to the description.
So far my approach:
#Function for computing area of a polygen
def polygonArea(A):
n = len(A) # of corners
area = 0.0
j = n - 1
for i in range(n):
area += (A[0][j] + A[0][i]) * (A[1][j] - A[1][i])
area = abs(area) / 2.0
#reading from the file and connecting the polygen in a vector array in terms of X and Y coordinates
file = input('Enter file name:')
with open(file, 'r') as f:
file = f.read()
fileContent =file
A = [[],[]] #trying to create an vector of x and y ordinates
xa = 0.0
yb = 0.0
data = ""
if fileContent > data and data == "(":
data.join(fileContent)
if data == "N":
data.join(fileContent)
if data != ",":
print("Description is wrong!")
if file>temp:
yb += temp
A[1].append(yb) #Storing the value in y co ordinate of vector A
A[0].append(xa) #Storing the value in x co ordinate of vector A
if data == "W":
data.join(fileContent)
if data != ",":
print("Description is wrong!")
if file > temp:
xa -= temp
A[1].append(yb)
A[0].append(xa)
if data == "E":
data.join(fileContent)
if data != ",":
print("Description is wrong!")
if file > temp:
xa += temp
A[1].append(yb)
A[0].append(xa)
if data == "S":
data.join(fileContent)
if data != ",":
print("Description is wrong!")
if file > temp:
xa -= temp
A[1].append(yb)
A[0].append(xa)
#If polygon is complete A CONDITION on completeion of polygen in c++ if(x.back()==0 && y.back()==0)
p= polygonArea(A)
print ("area = ",p)
