I need to convert a set of coordinates to the sublines and angle. Example:
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)]
Need to become: - line 1 = 1000 - line 2 = 500 - angle in between = 30º
I tried to calculate the arc length but no output comes close to what I need.
Example in 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))
This gives the following output:
-----------------------------------------
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
Any help is appreciated. Is this the right way to calculate this information? Any better way to use/calculate arc length?
The input coordinates come from a product that I can't influence. This is the data I need to use. I can only work on top of that data.