如何从一组xyz坐标计算长度和角度

时间:2016-11-07 16:54:54

标签: python pyx

我需要将一组坐标转换为子线和角度。 例如:

coords = [  (0.,0.,0.),
            (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),
            (1428.012701892219,0.,248.6602540378444)]

需要成为: - 第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.)]
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

感谢任何帮助。这是计算此信息的正确方法吗?有没有更好的方法来使用/计算弧长?

输入坐标来自我无法影响的产品。这是我需要使用的数据。我只能处理这些数据。

0 个答案:

没有答案