-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinear_interpolation_between_two_points.py
More file actions
executable file
·88 lines (80 loc) · 2.44 KB
/
linear_interpolation_between_two_points.py
File metadata and controls
executable file
·88 lines (80 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python
__author__="morganlnance"
'''
Give me two points( phi1, psi1 ) and ( phi2, psi2 ) and a number of steps to get between these points and this will print to screen the appropriate contents for a string_1.dat file of a linear interpolation between the given two points
Usage: python <script>.py phi1, psi1, phi2, psi2, steps
Args: python <script>.py float, float, float, float, int
'''
# imports
import sys
# get the right input arguments
# phi1
try:
phi1 = float( sys.argv[1] )
except IndexError:
print "\nGive me a phi value for your first point.\n"
sys.exit()
except ValueError:
print "\nI need a float for phi of the first point.\n"
sys.exit()
# psi1
try:
psi1 = float( sys.argv[2] )
except IndexError:
print "\nGive me a psi value for your first point.\n"
sys.exit()
except ValueError:
print "\nI need a float for psi of the first point.\n"
sys.exit()
# phi2
try:
phi2 = float( sys.argv[3] )
except IndexError:
print "\nGive me a phi value for your second point.\n"
sys.exit()
except ValueError:
print "\nI need a float for phi of the second point.\n"
sys.exit()
# psi2
try:
psi2 = float( sys.argv[4] )
except IndexError:
print "\nGive me a psi value for your second point.\n"
sys.exit()
except ValueError:
print "\nI need a float for psi of the second point.\n"
sys.exit()
# steps
try:
steps = int( sys.argv[5] )
except IndexError:
print "\nGive me the number of steps to get from point 1 to 2.\n"
sys.exit()
except ValueError:
print "\nI need an integer for the number of steps between point 1 to 2.\n"
sys.exit()
# get the distance between each step
phi_step = ( phi2 - phi1 ) / steps
psi_step = ( psi2 - psi1 ) / steps
# linear interpolation to get the coords
# plus one for steps because the first point should be phi1/psi1
phi_coords = [ round( phi1 + ( ii * phi_step ), 3 ) for ii in range( steps + 1 ) ]
psi_coords = [ round( psi1 + ( ii * psi_step ), 3 ) for ii in range( steps + 1) ]
phi_psi_coords = zip( phi_coords, psi_coords )
# keep phi,psi values within -180, 180
for ii in range( steps + 1 ):
phi = phi_psi_coords[ii][0]
psi = phi_psi_coords[ii][1]
while phi > 180:
phi -= 360
while phi < -180:
phi += 360
while psi > 180:
psi -= 360
while psi < -180:
psi += 360
# print to screen the appropriate lines
# for a string_1.dat file
print "# Image %s" %ii
print phi
print psi