1

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.

Gerrit Verhaar
  • 446
  • 4
  • 12
  • The distance calculation seems fine (though the cast to `float` is unnecessary). Where is your angle calculation? –  Nov 07 '16 at 16:59
  • @Evert - sorry for the late reply. I didn't get a reminder so need to check my settings. – Gerrit Verhaar Nov 21 '16 at 13:43
  • @Evert - when I have two lines I first shift them to the origin then use this function: `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)` – Gerrit Verhaar Nov 21 '16 at 13:48
  • @Evert - distance should be 1500. line 1 length (982,116) + arclen (14,833) + line 2 length (482.116) = 1479,065 – Gerrit Verhaar Nov 21 '16 at 14:08

0 Answers0