Python 如何从一组xyz坐标计算长度和角度
我需要将一组坐标转换成子线和角度。 例如: 需要成为: -第1行=1000 -第2行=500 -两者之间的角度=30º 我试图计算弧长,但没有输出接近我需要的 Python/Pyx中的示例:Python 如何从一组xyz坐标计算长度和角度,python,pyx,Python,Pyx,我需要将一组坐标转换成子线和角度。 例如: 需要成为: -第1行=1000 -第2行=500 -两者之间的角度=30º 我试图计算弧长,但没有输出接近我需要的 Python/Pyx中的示例: from pyx import * from pyx.metapost.path import beginknot, endknot, smoothknot, tensioncurve import math startLine = [(0.,0.,0.), (982.116098092115,0.,0.
from pyx import *
from pyx.metapost.path import beginknot, endknot, smoothknot, tensioncurve
import math
startLine = [(0.,0.,0.), (982.116098092115,0.,0.)]
x2,y2,z2 = startLine[1]
x1,y1,z1 = startLine[0]
distance = math.sqrt((float(x2) - float(x1))**2 +
(float(y2) - float(y1))**2 +
(float(z2) - float(z1))**2)
print ("-----------------------------------------")
print ("Line 1: length: " + str(distance))
arc = [ (982.116098092115,0.,0.),
(985.806272277749,0.,0.1737379990727277),
(989.5074251916399,0.,0.5718208697235241),
(993.1767690911661,0.,1.198652753820625),
(996.7726992359726,0.,2.0444504226557),
(1000.309764926028,0.,3.109933227386136),
(1003.800925900287,0.,4.401752841619327),
(1007.205259782333,0.,5.907579419769718),
(1010.487913371018,0.,7.602204991786948)
]
index = 0
for coord in arc:
x,y,z = coord
if ( index < 4):
xPrev, yPrev, zPrev = coord
index += 1
continue
elif ( index == 4):
p1 = path.path(path.moveto(xPrev, zPrev), path.lineto(x, z))
elif ( index == len(arc)-1):
print ("-----------------------------------------")
print (" arclen curve: " + str(p1.arclen()))
print ("-----------------------------------------")
else:
p1.append(path.lineto(x, z))
index += 1
endLine = [(1010.487913371018,0.,7.602204991786948), (1428.012701892219,0.,248.6602540378444)]
x2,y2,z2 = endLine[1]
x1,y1,z1 = endLine[0]
distance = math.sqrt((float(x2) - float(x1))**2 +
(float(y2) - float(y1))**2 +
(float(z2) - float(z1))**2)
print ("Line 2: length: " + str(distance))
感谢您的帮助。这是计算这些信息的正确方法吗?有没有更好的方法来使用/计算弧长
输入坐标来自我无法影响的产品。这是我需要使用的数据。我只能在这些数据的基础上工作。距离计算似乎很好(尽管不需要转换为
float
)。“你的角度计算在哪里?”埃弗特-很抱歉回复晚了。我没有收到提醒,所以需要检查我的设置。@Evert-当我有两行时,我首先将它们移到原点,然后使用此函数:def calculate_angle(coord1,coord2):num=np.dot(coord1,coord2)denom=np.linalg.norm(coord1)*np linalg.norm(coord2)angle=int(np.arccos(num/denom)*180/np.pi)return(angle)
@Evert-距离应为1500。第1行长度(982116)+arclen(14833)+第2行长度(482.116)=1479065距离计算似乎很好(尽管不需要转换为float
)。“你的角度计算在哪里?”埃弗特-很抱歉回复晚了。我没有收到提醒,所以需要检查我的设置。@Evert-当我有两行时,我首先将它们移到原点,然后使用此函数:def calculate_angle(coord1,coord2):num=np.dot(coord1,coord2)denom=np.linalg.norm(coord1)*np linalg.norm(coord2)angle=int(np.arccos(num/denom)*180/np.pi)return(angle)
@Evert-距离应为1500。1号线长度(982116)+arclen(14833)+2号线长度(482.116)=1479065
from pyx import *
from pyx.metapost.path import beginknot, endknot, smoothknot, tensioncurve
import math
startLine = [(0.,0.,0.), (982.116098092115,0.,0.)]
x2,y2,z2 = startLine[1]
x1,y1,z1 = startLine[0]
distance = math.sqrt((float(x2) - float(x1))**2 +
(float(y2) - float(y1))**2 +
(float(z2) - float(z1))**2)
print ("-----------------------------------------")
print ("Line 1: length: " + str(distance))
arc = [ (982.116098092115,0.,0.),
(985.806272277749,0.,0.1737379990727277),
(989.5074251916399,0.,0.5718208697235241),
(993.1767690911661,0.,1.198652753820625),
(996.7726992359726,0.,2.0444504226557),
(1000.309764926028,0.,3.109933227386136),
(1003.800925900287,0.,4.401752841619327),
(1007.205259782333,0.,5.907579419769718),
(1010.487913371018,0.,7.602204991786948)
]
index = 0
for coord in arc:
x,y,z = coord
if ( index < 4):
xPrev, yPrev, zPrev = coord
index += 1
continue
elif ( index == 4):
p1 = path.path(path.moveto(xPrev, zPrev), path.lineto(x, z))
elif ( index == len(arc)-1):
print ("-----------------------------------------")
print (" arclen curve: " + str(p1.arclen()))
print ("-----------------------------------------")
else:
p1.append(path.lineto(x, z))
index += 1
endLine = [(1010.487913371018,0.,7.602204991786948), (1428.012701892219,0.,248.6602540378444)]
x2,y2,z2 = endLine[1]
x1,y1,z1 = endLine[0]
distance = math.sqrt((float(x2) - float(x1))**2 +
(float(y2) - float(y1))**2 +
(float(z2) - float(z1))**2)
print ("Line 2: length: " + str(distance))
-----------------------------------------
Line 1: length: 982.116098092115
-----------------------------------------
arclen curve: (0.148331 t + 0.000000 u + 0.000000 v + 0.000000 w + 0.000000 x) m
-----------------------------------------
Line 2: length: 482.11609809211416