python 存储坐标_arrays - 如何在Python中创建用于存储多边形的x和y坐标的数组 - SO中文参考 - www.soinside.com...

如何在Python中创建用于存储多边形的x和y坐标的数组

问题描述 投票:0回答:4

因此,我试图从文件中读取多边形的描述,并给出方向及其移动到目前为止,我的方法是btw(我是python的菜鸟,而c ++具有背景,因此代码可能有很多语法错误)与c ++的相似性]def Area(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)

arrays

4个回答

1

投票

[这里,我定义了一个函数,该函数将吸收多边形的长度,从长度为17.5的垂直线处的线开始,并顺时针进行:

1

投票

这可以帮助您入门;这显示了从文件中读取元素。关于处理“每个”列表,您应该能够填写其余的内容。在这里,我们将根据“)”字符分割输入,然后将每个分割成可以使用的格式。您需要N-S-E-W,还有一个值,对吗?可能希望使用.upper或其他调整项,以便您不必担心大小写('e'与'E')...

1

投票

这里是一个完整的解决方案。首先,我们使用正则表达式解析数据,找到基本方向并在每对括号内移动。

0

投票

如果可以获取从任何顶点开始的所有点的顺时针或逆时针方向的坐标,则可以使用以下公式:eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9tdzZORS5wbmcifQ==

热门问题

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值