-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2 KEPLER.py
128 lines (102 loc) · 2.12 KB
/
2 KEPLER.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 16 20:13:08 2020
@author: kpurc
"""
import matplotlib.pyplot as plt
import numpy as np
import scipy
#from scipy import stats
#from scipy import signal
import math
from matplotlib.animation import FuncAnimation
pi = math.pi #pi
P = 3963 #3962.86 #weeks
tp = 0
t = 0 #time steps in weeks
e= 0.967
rp = 0.587 #AU
a = 17.78788 #AU
ra = 34.98876 #AU
#1
M = []
while t < 3963:
M.append(2*pi*(((t-tp)%P)/P))
t = t+1
stand = [i for i in range(3963)]
#plt.scatter(M, stand)
#2
n=0
En2=[]
t=0
while t<3963:
n=0
En = M[t]
while n < 100:
En1 = En-((En-(e*math.sin(En))-M[t])/(1-(e*math.cos(En))))
En = En1
n = n+1
En2.append(En1)
t=t+1
#plt.scatter(En2, stand)
#3a
Q=[]
t=0
while t < 3963:
Q.append((math.sqrt((1+e)/(1-e)))*math.tan(En2[t]/2))
t=t+1
#3b THIS IS IN RAD
t=0
H=[]
while t < 3963:
H.append(math.atan(Q[t])*2)
t=t+1
#plt.scatter(H, stand)
#4
t=0
rt=[]
while t<3963:
rt.append((a*(1-e**2))/(1+e*math.cos(H[t])))
t=t+1
#plt.scatter(rt, stand)
#making the x,y coordinate system
t=0
x=[]
y=[]
while t < 3963:
x.append(rt[t]*math.cos(H[t]))
y.append(rt[t]*math.sin(H[t]))
t=t+1
fig1=plt.figure(1)
plt.polar(H,rt)
plt.polar(0,0)
plt.show()
print(np.sort(x))
fig2=plt.figure(2)
plt.scatter(x, y)
plt.scatter(0,0)
plt.title('Halleys Comet Orbit around the Sun')
plt.xlabel('Distance in AU')
plt.ylabel('Distance in AU')
#plt.xlim(right=3, left=-3)
#plt.ylim(bottom=-3, top=3)
'''
#ANIMATING
'''
fig, ax = plt.subplots()
ln, = plt.plot([], [], 'go')
def init():
ax.set_xlim(-40, 5)
ax.set_ylim(-5, 5)
return ln,
def update(frame):
ln.set_data(x[:frame], y[:frame])
return ln,
ani = FuncAnimation(fig, update, frames=np.arange(0, 3963, 30),
init_func=init, blit=True)
plt.title('Halleys Comet Orbit around the Sun')
plt.xlabel('Distance in AU')
plt.ylabel('Distance in AU')
plt.scatter(x,y, 1)
plt.scatter(0,0)
plt.show()