Skip to content

Commit a81877c

Browse files
Update black hole simulation - faster.py
1 parent c52ea3e commit a81877c

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Diff for: black hole simulation - faster.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def integration(D,alpha):
6868
return [0],[0] #r and phi=0
6969
if alpha==180:
7070
return [D],[0] # if angle= pi then, tan(pi)=0 so 1/tan=1/0
71-
y0=[1/D, 1/(D*math.tan(alpha*math.pi/180))] #initial value for position and angular speed
71+
y0=[1/D, 1/(D*math.tan(math.radians(alpha)))] #initial value for position and angular speed
7272
sol=solve_ivp(fun=fun, t_span=[0,t_max], y0=y0, method='Radau',dense_output=False, events=[eventRs])#,eventR])#,t_eval=np.linspace(0,t_max,10000))
7373
if sol.t[-1]==t_max:
7474
raise StopIteration ("integration error, alpha reached computing limit (loop number)")
@@ -127,7 +127,7 @@ def search_alpha_min(D,img_res,Rs):
127127
r,phi=integration(D,alpha)
128128
if r[-1]>Rs*1.1: #if not capture by black hole
129129
seen_angle.append(180-alpha) #put 180 in the center
130-
deviated_angle.append(180/math.pi*(phi[-1]+math.asin(D/r[-1]*math.sin(phi[-1]))))
130+
deviated_angle.append(math.degrees((phi[-1]+math.asin(D/r[-1]*math.sin(phi[-1])))))
131131
Ci='C'+str(i)
132132
ax.plot(phi,r,Ci) #plot one trajectory
133133
if kind=='linear':
@@ -200,8 +200,6 @@ def listdirectory2(path,matrix_file):
200200
return False
201201
# =============================================================================
202202
def spheric2cart(theta,phi):
203-
# theta=theta/180*math.pi
204-
# phi=phi/180*math.pi
205203
x = math.sin(theta) * math.cos(phi)
206204
y = math.sin(theta) * math.sin(phi)
207205
z = math.cos(theta)
@@ -212,15 +210,14 @@ def cart2spheric(x,y,z):
212210
theta=math.acos(z)
213211
phi=math.atan2(y,x)
214212
while phi<0: #define phi [0,360]
215-
phi+=2*math.pi
213+
phi+=math.radians(360)
216214
while theta<0: # define theta [0,180]
217215
theta+=math.pi
218-
if phi==2*math.pi:
216+
if phi==math.radians(360):
219217
phi=0
220218
return theta,phi
221219
# =============================================================================
222220
def rotation_matrix(beta):
223-
# beta*=math.pi/180
224221
"""from https://stackoverflow.com/questions/6802577/rotation-of-3d-vector
225222
Return the rotation matrix associated with counterclockwise rotation about
226223
the x axis by beta degree."""

0 commit comments

Comments
 (0)