-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_vtarg.py
73 lines (54 loc) · 1.61 KB
/
test_vtarg.py
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
from signal import pause
from turtle import pos
import numpy as np
import matplotlib.pyplot as plt
def main():
initial_conditions = [-1600, 2000, np.pi*3/4, 180, -90, 0, 50e3]
r_0 = initial_conditions[0:2]
v_0 = initial_conditions[3:5]
r_f = [0,0]
v_f = [0,0]
positions = np.linspace(start=r_0, stop=r_f, num=200)
velocities = np.linspace(start=v_0, stop=v_f, num=200)
trajectory = zip(positions, velocities)
vtargs = []
tgos = []
for r,v in trajectory:
vtarg, tgo = _compute_vtarg(r,v,IC=initial_conditions)
vtargs.append(vtarg)
tgos.append(tgo)
# Compute the velocity quiver plot
fig, ax = plt.subplots()
x_pos = [pos[0] for pos in positions]
y_pos = [pos[1] for pos in positions]
U = [v[0] for v in vtargs]
V = [v[1] for v in vtargs]
# Let's add some color
n=-2
vmags = [np.sqrt(u**2+v**2) for u,v in zip(U,V)]
ax.quiver(x_pos, y_pos, U, V, tgos, alpha=0.8, units='xy',width=10)
fig1,ax1=plt.subplots()
ax1.plot(vmags)
plt.show()
pause()
def _compute_vtarg(r, v, IC):
tau_1 = 100
tau_2 = 100
initial_conditions = IC
v_0 = np.linalg.norm(initial_conditions[3:5])
# if r[1]>15:
# r_hat = r-[0,15]
# v_hat = v-[0,-2]
# tau = tau_1
#else:
# r_hat = [0,15]
# v_hat = v-[0,-1]
# tau = tau_2
r_hat = r
v_hat = v
tau = 20
t_go = np.linalg.norm(r_hat)/np.linalg.norm(v_hat)
v_targ = -v_0*(r_hat/np.linalg.norm(r_hat))*(1-np.exp(-t_go/tau))
return v_targ, t_go
if __name__ == '__main__':
main()