Project Kerr
Project Kerr
1 Introduction
Black holes are one of the most intriguing aspects of Einstein’s theory of general relativity. In popular culture, it has
been the subject of many misconceptions. Recently, the Hollywood production Interstellar has however delivered to
general audiences high quality depictions of black holes based on serious science [JvTFT15].
For this project, we are interested in understanding how physically (relatively) accurate visual representations of
rotating black holes are obtained. Concretely, we create in MATLAB a ray tracer for a Kerr geometry describing the
surroundings of a rotating black hole.
We start by briefly describing the geometry of Kerr space-time. Then, we present a toy model for vision and ray
tracing before moving on to numerical implementation.
t = t,
p
x = r2 + a2 sin θ cos φ,
p
y = r2 + a2 sin θ sin φ,
z = r cos θ.
The Kerr metric is the non-degenerate symmetric 2-tensor given, for r large enough, by
∆ sin2 θ 2 Σ
− (dt − a sin2 θ dφ)2 + ((r + a2 ) dφ − a dt)2 + dr2 + Σ dθ2 , (1)
Σ Σ ∆
with
∆(r) := r2 − Rr + a2 ,
Σ(r, θ) := r2 + a2 cos2 θ,
1
Final Project – MATH 599 R. Raquépas and E. Schulz
where R = 2M and a = JM −1 are parameters determined by the mass M and angular momentum J of the black hole.
We work in Plank units G = 1, c = 1. Note that this metric is invariant under the transformation (R, a; t, r, θ, φ) 7→
(R, −a; −t, r, θ, φ). Also note that we recover the Schwarzschild metric when a = 0 and that this Kerr metric is
approximately flat for r a, R. Finally, we remark that metric coefficients diverge as ∆(r) → 0, i.e. as r →
1
√ √
2 (R ± R2 − 4a2 ) = M ± M 2 − a2 .
In the basis (∂t , ∂r , ∂θ , ∂φ ) for tangent spaces, the metric has matrix form
sin2 (θ)
− 1 − Σ(r,θ)Rr
0 0 − Rra Σ(r,θ)
Σ(r,θ)
0 ∆(r) 0 0
g= .
0 0 Σ(r, θ)
0
2 2 2 2 2 2
2 sin (θ) (a +r ) −a ∆(r) sin (θ)
− Rra sin (θ)
Σ(r,θ) 0 0 Σ(r,θ)
2
Final Project – MATH 599 R. Raquépas and E. Schulz
where xµ = γ µ and pµ = gµλ γ̇ λ . In practice, we will solve this system of first order ODEs using a Runge–Kutta-4
method.
We also take advantage of conserved quantities arising from Noether’s theorem. These conserved quantities are
the angular momentum arising from the Killing vector field ∂φ
Ra Ra2
L=− ṫ + r2 + a2 + φ̇
r r
and the energy arising from the Killing vector field ∂t
r Ra
E = 1− ṫ + φ̇.
R r
It is based on the fact that the solution X to such a system satisfies the approximation
h
X(λ + h) = X(λ) + (f1 (λ, X(λ)) + f2 (λ, X(λ)) + f3 (λ, X(λ)) + f4 (λ, X(λ))) + O(h5 ) (2)
6
where
We do not prove this well-known approximation, which is obtained through a clever Taylor expansion.
We use this Runge–Kutta to integrate the geodesic equations where
X = (x0 , . . . , x3 , p0 , . . . , p3 )
and
∂H ∂H ∂H ∂H
F = ( ∂p 0
, . . . , ∂p3
, − ∂x 0 , . . . , − ∂x3 ).
We use a step size h proportional to ∆(r), because some coefficients in the equation blow up as ∆(r)−1 near the
horizon.
3 Ray tracer
3.1 Toy model for ray tracing
To understand better how to generate images of Kerr black holes, we pause and take a look at a toy model for vision in
flat space-time. Consider an eye (or camera) modelled by a point pupil P and a retina (or screen) R, and light sources,
say a star Si . The sources Si emits light in all directions, in straight line, and (only) the rays that pass through the
pupil P are then recorded on the retina R, which we think of as an indexed array of pixels. The color of the source is
recorded at the corresponding pixel of the retina.
3
Final Project – MATH 599 R. Raquépas and E. Schulz
∗ S1
•
P
R
∗ S2
∗ S1
•
P
R
∗ S2
It turns out that it is computationally more convenient to think of this problem in reverse and see what sources
light rays leaving each pixel of the retina: if the emitted ray hits no source, the pixel gets no input (black) and if it hits
source Si , then it gets the color of this source.
This toy model evacuates notions of focus and many other details but is good enough for our purposes. In our
set up the sources will be placed on a celestial sphere of large radius centred at the black hole. The main difficulty
becomes that because of the curvature of the Kerr metric, light does not travel in straight lines. For each ray leaving
the retina, we must solve non-trivial geodesic equations to obtain the source it hits. We will also have to deal with
horizons and add an accretion disk.
4
Final Project – MATH 599 R. Raquépas and E. Schulz
ṫ(0) = 1,
dP
ẋ(0) = p ,
d2P + h2 + w2
w
ẏ(0) = p ,
d2P + h2 + w2
h
ż(0) = p .
d2P + h2 + w2
Note that this vector would be light-like in flat space-time and is therefore approximately light-like in the regime
r(0) R, a. Pushed in Boyer–Lindquist coordinates, using the Jacobian of the coordinates transformations,
ṫ(0) = 1,
p
2 r(0) a2 + r(0)2 dP sin θ(0) + h a2 + r(0)2 cos θ(0)
ṙ(0) = p ,
d2P + h2 + w2 (a2 cos(2θ(0)) + a2 + 2r(0)2 )
p
2 a2 + r(0)2 dP cos θ(0) − hr(0) sin θ(0)
θ̇(0) = p 2 ,
dP + h2 + w2 (a2 cos(2θ(0)) + a2 + 2r(0)2 )
w csc θ(0)
φ̇(0) = p .
(a2 + r(0)2 ) (d2P + h2 + w2 )
5
Final Project – MATH 599 R. Raquépas and E. Schulz
1. the ray exiting the camera leaves hits the celestial sphere far from the black hole;
In the first case, hitting the celesting sphere means that a given step of the RK4 results in a point outside the celestial
sphere. A choice should then be made to keep the coordinates of the point closest to the sphere. These coordinates are
stored, and they are later used to generate the corespondence between the RGB value of each pixel given an image. In
the second step, we approach the black hole with adaptive steps to prevent blow up. If we a ray steps close within a
margin error to the black hole, we consider that it enters the event horizon. A boolean is kept to indicate the the RGB
triple associated to that pixel should indicate pure black.
-10
-20
-30
-40
-50
-60
-70
0
-60 -40 -20 0 20 40 60
Figure 2: The rays emanate from the camera on the right of the image: some enter the event horizon (black sphere);
others continue their curved trajectory until they hit the celestial sphere.
6
Final Project – MATH 599 R. Raquépas and E. Schulz
This last situation is treated independently of the two cases presented in the last section, so that the user can choose
whether to generate the accretion disk or not. The proceedure is in that case similar.
Figure 3: The rays passing near the z-axis behave wildly, causing a serious defect at the center of the image.
5
-5 0
-5
8 6 4 2 -10
0 -2
7
Final Project – MATH 599 R. Raquépas and E. Schulz
We get around this problem by sneakily removing a certain number of columns of pixels in the middle of the
image... More on this in Section 5.
5 Possible improvements
Although we are satisfied (given the time that was available) with the images generated, there are a few things that
we have not taken into account and that would improve the realism of the depiction. First, as we mentioned earlier,
the problem with the Boyer–Lindquist coordinates in the vicinity of at θ = 0 and θ = π should be taken care of by
a proper change of coordinates. Also, we have not considered the fact that the light rays emitted by the stars should
undergo gravitational red-shift. Indeed, we should adjust the color of the pixels according to this effet. Moreover, our
treatment of what happens near — but not quite inside — the event horizon is rather crude.
References
[AF13] Marek A. Abramowicz and P. Chris Fragile, Foundations of black hole accretion disk theory, Living
Reviews in Relativity 16 (2013), no. 1, 1.
[JvTFT15] Oliver James, Eugénie von Tunzelmann, Paul Franklin, and Kip S Thorne, Gravitational lensing by spin-
ning black holes in astrophysics, and in the movie interstellar, Classical and Quantum Gravity 32 (2015),
no. 6, 065001.
[Ker63] Roy P. Kerr, Gravitational field of a spinning mass as an example of algebraically special metrics, Phys.
Rev. Lett. 11 (1963), 237–238.
8
Final Project – MATH 599 R. Raquépas and E. Schulz
% M e t r i c r e l a t e d d a t a and e q s .
G = 1; % g r a v i t a t i o n a l constant
M = 1 ; % mass o f b l a c k h o l e
a = 0 . 6 ; % Kerr ( sp in ) parameter
R = 2 ∗ G ∗ M;
r a d i u s c e l e s t i a l s p h e r e = 80;
aDiskMin = 2∗R ;
aDiskMax = 5∗R ;
% Some p h y s i c a l f o r m u l a s ( u s e d t o l i g h t e n n o t a t i o n )
Sigma = @( r , t h e t a ) r ˆ 2 + a ˆ 2 ∗ c o s ( t h e t a ) ˆ 2 ;
d r S i g m a = @( r ) 2 ∗ r ;
d t h e t a S i g m a = @( t h e t a ) − 2∗ a ˆ 2 ∗ c o s ( t h e t a ) ∗ s i n ( t h e t a ) ;
D e l t a = @( r ) r ˆ 2 − R ∗ r + a ˆ 2 ;
d r D e l t a = @( r ) 2 ∗ r − R ;
% P h y s i c a l d i m e n s i o n s o f o b s e r v a t i o n a l window
window height = 0.00001;
w i n d o w w i d t h = ( r e s o l u t i o n w i d t h / r e s o l u t i o n h e i g h t )∗ w i n d o w h e i g h t ;
d i s t a n c e f r o m w i n d o w = −2∗0.000007;
% I n i t i a l i z e c o o r d i n a t e s m a t r i c e s f o r image mapping
% coords no aDisk ( i , j , 1 ) : theta
% coords no aDisk ( i , j , 2 ) : phi
% coords no aDisk ( i , j , 3 ) : 1 i f stopped at R
% 0 i f stopped at r a d i u s c e l e s t i a l s p h e r e
coords no aDisk = zeros ( resolution height , resolution width , 3 ) ;
% coords aDisk ( i , j , 1 ) : radius
% coords aDisk ( i , j , 2 ) : phi
% coords aDisk ( i , j , 3 ) : 0 i f did not h i t a c c r e t i o n disk
% 1 i f pass through accretion disk
coords aDisk = zeros ( resolution height , resolution width , 3 ) ;
s t e p s i z e = 0 . 1 ; % s t e p s i z e f o r Runge−K u t t a 4
h b a r = p a r f o r p r o g r e s s b a r ( r e s o l u t i o n w i d t h , ’ P l e a s e w a i t . . . ’ ) ; %c r e a t e t h e p r o g r e s s b a r ( r e s o l u t i o n w i d t h ) ;
for j = 1: resolution width
h b a r . i t e r a t e ( 1 ) ; % u p d a t e p r o g r e s s by one i t e r a t i o n
for i = 1: r e s o l u t i o n h e i g h t
% P i x e l s l o c a t i o n on o b s e r v a t i o n a l window ( we ommit t h e v e r t i c a l
% s i n g u l a r i t y a t p i / 2 by i n t r o d u c i n g a jump : s i n g u l a r i t y h a c k )
%s i n g u l a r i t y h a c k = 0 . 0 1 ;
% i f j < r e s o l u t i o n w i d t h / 2 − s i n g u l a r i t y h a c k∗r e s o l u t i o n w i d t h
% h = w i n d o w h e i g h t / 2 − ( i −1) ∗ w i n d o w h e i g h t / ( r e s o l u t i o n h e i g h t −1);
9
Final Project – MATH 599 R. Raquépas and E. Schulz
% w = −w i n d o w w i d t h / 2 + ( j −1) ∗ w i n d o w w i d t h / ( r e s o l u t i o n w i d t h −1);
% else
% h = w i n d o w h e i g h t / 2 − ( i −1) ∗ w i n d o w h e i g h t / ( r e s o l u t i o n h e i g h t −1);
% w = −w i n d o w w i d t h / 2 + ( s i n g u l a r i t y h a c k ∗w i n d o w w i d t h ) + ( j −1) ∗ w i n d o w w i d t h / ( r e s o l u t i o n w i d t h −1);
% end
%
h = w i n d o w h e i g h t / 2 − ( i −1) ∗ w i n d o w h e i g h t / ( r e s o l u t i o n h e i g h t −1);
w = −w i n d o w w i d t h / 2 + ( j −1) ∗ w i n d o w w i d t h / ( r e s o l u t i o n w i d t h −1);
% I n i t i a l i z i n g i n i t i a l conditions
r = 70;
t h e t a = pi /2 − pi / 4 6 ; % o f f s e t th e b l a c k h o l e to see with of aDisk
phi = 0;
t dot = 1;
p h i d o t = ( c s c ( t h e t a ) ∗ w ) / s q r t ( ( a ˆ 2 + r ˆ 2 ) ∗ ( d i s t a n c e f r o m w i n d o w ˆ 2 + wˆ 2 + h ˆ 2 ) ) ;
p r = 2 ∗ Sigma ( r , t h e t a ) ∗ ( h ∗ ( a ˆ 2 + r ˆ 2 ) ∗ c o s ( t h e t a ) + r ∗ s q r t ( a ˆ 2 + r ˆ 2 ) ∗ s i n ( t h e t a ) ∗ d i s t a n c e f r o m w i n d o w ) . . .
/ ( s q r t ( d i s t a n c e f r o m w i n d o w ˆ 2 + h ˆ 2 + wˆ 2 ) ∗ ( a ˆ 2 + 2 ∗ r ˆ 2 + a ˆ 2 ∗ c o s (2∗ t h e t a ) ) ∗ D e l t a ( r ) ) ;
p t h e t a = 2 ∗ Sigma ( r , t h e t a ) ∗ ( −h ∗ r ∗ s i n ( t h e t a ) + s q r t ( a ˆ 2 + r ˆ 2 ) ∗ c o s ( t h e t a ) ∗ d i s t a n c e f r o m w i n d o w ) . . .
/ ( s q r t ( d i s t a n c e f r o m w i n d o w ˆ 2 + h ˆ 2 + wˆ 2 ) ∗ ( a ˆ 2 + 2 ∗ r ˆ 2 + a ˆ 2 ∗ c o s (2∗ t h e t a ) ) ) ;
% Conserved q u a n t i t i e s ( i n s t a n t i a t e d with I .C . )
E = ( 1 − R/ r ) ∗ t d o t + ( R ∗ a ∗ phi dot ) / r ;
L = − ( R ∗ a ) / r ∗ t d o t + ( r ˆ2 + a ˆ2 + ( R ∗ a ˆ2 ) / r ) ∗ p h i d o t ;
% G e o d e s i c e q u a t i o n s ( s y s t e m o f f i r s t o r d e r ODEs )
% input : x = [ r ; t h e t a ; phi ; pr ; p t h e t a ]
% o u p u t : dx = [ d r ; d t h e t a ; d p h i ; d p r ; d p t h e t a ] ” x d o t ”
f = @( lambda , x ) [ ( x ( 4 ) ∗ D e l t a ( x ( 1 ) ) ) / Sigma ( x ( 1 ) , x ( 2 ) ) ;
x ( 5 ) / Sigma ( x ( 1 ) , x ( 2 ) ) ;
( a ∗ ( −a ∗ L + x ( 1 ) ∗ R ∗ E ) + L ∗ c s c ( x ( 2 ) ) ˆ 2 ∗ D e l t a ( x ( 1 ) ) ) / ( D e l t a ( x ( 1 ) ) ∗ Sigma ( x ( 1 ) , x ( 2 ) ) ) ;
− ( 1 / ( 2 ∗ D e l t a ( x ( 1 ) ) ˆ 2 ∗ Sigma ( x ( 1 ) , x ( 2 ) ) ˆ 2 ) ) ∗ ( Sigma ( x ( 1 ) , x ( 2 ) ) ∗ (−E ∗ D e l t a ( x ( 1 ) ) ∗ . . .
( a ∗ R ∗ ( −2 ∗ L + a ∗ E ∗ s i n ( x ( 2 ) ) ˆ 2 ) + 2 ∗ x ( 1 ) ∗ E ∗ Sigma ( x ( 1 ) , x ( 2 ) ) ) . . .
+ ( a ∗ ( a ∗ Lˆ2 − 2 ∗ L ∗ x ( 1 ) ∗ R ∗ E + a ∗ x ( 1 ) ∗ R ∗ Eˆ2 ∗ s i n ( x ( 2 ) ) ˆ 2 ) + x ( 4 ) ˆ 2 ∗ . . .
D e l t a ( x ( 1 ) ) ˆ 2 + ( a ˆ 2 + x ( 1 ) ˆ 2 ) ∗ E ˆ 2 ∗ Sigma ( x ( 1 ) , x ( 2 ) ) ) ∗ d r D e l t a ( x ( 1 ) ) ) . . .
+ D e l t a ( x ( 1 ) ) ∗ ( a ∗ ( L ∗ ( a ∗ L − 2 ∗ x ( 1 ) ∗ R ∗ E )+ a ∗ x ( 1 ) ∗ R ∗ Eˆ2 ∗ s i n ( x ( 2 ) ) ˆ 2 ) . . .
− D e l t a ( x ( 1 ) ) ∗ ( x ( 5 ) ˆ 2 + Lˆ2 ∗ csc ( x ( 2 ) ) ˆ 2 + x ( 4 ) ˆ 2 ∗ D e l t a ( x ( 1 ) ) ) ) ∗ drSigma ( x ( 1 ) ) ) ;
−( 1 / ( 2 ∗ D e l t a ( x ( 1 ) ) ∗ Sigma ( x ( 1 ) , x ( 2 ) ) ˆ 2 ) ) ∗ ( −2 ∗ s i n ( x ( 2 ) ) ∗ ( a ˆ 2 ∗ x ( 1 ) ∗ R ∗ E ˆ 2 ∗ c o s ( x ( 2 ) ) . . .
+ L ˆ 2 ∗ c o t ( x ( 2 ) ) ∗ c s c ( x ( 2 ) ) ˆ 3 ∗ D e l t a ( x ( 1 ) ) ) ∗ Sigma ( x ( 1 ) , x ( 2 ) ) . . .
+ ( a ∗ (L ∗ ( a ∗ L − 2 ∗ x ( 1 ) ∗ R ∗ E ) + a ∗ x ( 1 ) ∗ R ∗ Eˆ2 ∗ s i n ( x ( 2 ) ) ˆ 2 ) − Delta ( x ( 1 ) ) . . .
∗ ( x ( 5 ) ˆ 2 + Lˆ2 ∗ csc ( x ( 2 ) ) ˆ 2 + x ( 4 ) ˆ 2 ∗ Delta ( x ( 1 ) ) ) ) ∗ dthetaSigma ( x ( 2 ) ) ) ] ;
% S o l v i n g f o r t h e g e o d e s i c s u s i n g Runga−K u t t a 4
% RK4 p a r a m e t e r s
x 0 = [ r ; t h e t a ; phi ; p r ; p t h e t a ] ;
curve = x 0 ’ ;
% Clean c o o r d i n t a t e s v a l u e s
c u r v e ( k , 2 ) = mod ( c u r v e ( k , 2 ) , 2 ∗ p i ) ;
c u r v e ( k , 3 ) = mod ( c u r v e ( k , 3 ) , 2 ∗ p i ) ;
i f curve (k , 2 ) > pi
c u r v e ( k , 2 ) = 2∗ p i − c u r v e ( k , 2 ) ;
c u r v e ( k , 3 ) = mod ( p i + c u r v e ( k , 3 ) , 2 ∗ p i ) ;
end
k = k +1;
% Use Runge−K u t t a 4 s t e p t o e v o l v e g e o d e s i c c u r v e
% Some a d a p t a t i v i t y i s o b t a i n e d by m u l t i p l y i n g s t e p s i z e
% by D e l t a , which s c a l e i n v e r s l y t o t h e c o o r d i n a t e s
% s i n g u l a r i t y near the event horizon
c u r v e ( k , : ) = r k 4 s t e p ( f , 0 , c u r v e ( k −1 ,:) ’ , min ( [ s t e p s i z e ∗D e l t a ( c u r v e ( k − 1 , 1 ) ) ; s t e p s i z e ] ) ) ’ ;
end
% T r a n s f o r m t o e u c l i d e a n c o o r d i n a t e s and p l o t 3
[ n ,m] = s i z e ( c u r v e ) ;
A = a∗o n e s ( n , 1 ) ;
B o y e r 2 C a r t = @( r , t h e t a , p h i ) [ s q r t ( r . ˆ 2 + A . ˆ 2 ) . ∗ s i n ( t h e t a ) . ∗ c o s ( p h i ) , . . .
s q r t ( r . ˆ 2 + A. ˆ 2 ) . ∗ s i n ( t h e t a ).∗ s i n ( phi ) , . . .
r .∗ c o s ( t h e t a ) ] ;
c a r t = Boyer2Cart ( curve ( : , 1 ) , curve ( : , 2 ) , curve ( : , 3 ) ) ;
plot3 ( cart (: ,1) , cart (: ,2) , cart ( : , 3 ) ) ;
case 0
k = 1; % keeping count of s t e p s
passed through aDisk = 0;
% C u r v e s s t e p s a r e computed w i t h i n t h e c e l e s t i a l s p h e r e where t h e y e x i s t
w h i l e ( 1 . 2 ∗R < c u r v e ( 1 ) ) && ( c u r v e ( 1 ) < r a d i u s c e l e s t i a l s p h e r e ) && ( k <20000)
% Use Runge−K u t t a t o t a k e a t e m p o r a r y s t e p f o w a r d
t e m p c u r v e s t e p = r k 4 s t e p ( f , 0 , c u r v e ’ , min ( [ s t e p s i z e ∗D e l t a ( c u r v e ( 1 ) ) ; s t e p s i z e ] ) ) ’ ;
10
Final Project – MATH 599 R. Raquépas and E. Schulz
i f p a s s e d t h r o u g h a D i s k == 0
% Check i f t h e t e m p o r a r y s t e p go t h r o u g h t h e a c c r e t i o n d i s k
i f ( t e m p c u r v e s t e p (2)− p i / 2 ) ∗ ( c u r v e (2)− p i / 2 ) < 0
i f ( aDiskMin < t e m p c u r v e s t e p ( 1 ) ) && ( t e m p c u r v e s t e p ( 1 ) < aDiskMax )
coords aDisk ( i , j , : ) = [ temp curve step ( 1 ) ; temp curve step ( 3 ) ; 1];
passed through aDisk = 1;
end
end
end
% Clean c o o r d i n a t e s v a l u e s
c u r v e ( 2 ) = mod ( c u r v e ( 2 ) , 2 ∗ p i ) ;
c u r v e ( 3 ) = mod ( c u r v e ( 3 ) , 2 ∗ p i ) ;
i f curve (2) > pi
c u r v e ( 2 ) = 2∗ p i − c u r v e ( 2 ) ;
c u r v e ( 3 ) = mod ( p i + c u r v e ( 3 ) , 2 ∗ p i ) ;
end
k = k +1;
end
% Save c o o r d i n a t e s a c c o r d i n g t o c a s e s
i f ( 1 . 2 ∗R < c u r v e ( 1 ) )
coords no aDisk ( i , j , : ) = [ curve ( 2 ) ; curve ( 3 ) ; 0 ] ;
else
coords no aDisk ( i , j , : ) = [ curve ( 2 ) ; curve ( 3 ) ; 1 ] ;
end
end
end
end
close ( hbar ) ;
i f p l o t t y p e == 1
hold off
end
% Save c o o r d i n a t e s a s m a l t a b f i l e
s a v e img Map no BH c o o r d s n o a D i s k c o o r d s a D i s k aDiskMin aDiskMax ;
%% G e n e r a t i n g f i n a l i m a g e s from d i f f e r e n t c e l e s t i a l scenes
l o a d ( ’ img Map no BH ’ ) ;
a c c r e t i o n d i s k s c e n e = i m r e a d ( ’ a d i s k s k e w e d . png ’ ) ;
[ accretion scene height res , accretion scene width res , ˜] = size ( accretion disk scene );
k = 1;
switch k
case 1
c e l e s t i a l s c e n e = imread ( ’ GriddedGal . jpg ’ ) ;
case 2
c e l e s t i a l s c e n e = imread ( ’ I n t e r s t e l l a r W o r m h o l e F i g 6 b . jpg ’ ) ;
case 3
c e l e s t i a l s c e n e = imread ( ’ I n t e r s t e l l a r W o r m h o l e F i g 1 0 . jpg ’ ) ;
end
IMG = z e r o s ( r e s o l u t i o n h e i g h t , r e s o l u t i o n w i d t h , 3 , ’ u i n t 8 ’ ) ;
% G e n e r a t e image
for j = 1: resolution width
for i = 1: r e s o l u t i o n h e i g h t
i f i m a g e t y p e w i t h d i s k == 1
i f b o o l e a n a D i s k == 1
i f c o o r d s a D i s k ( i , j , 3 ) == 1
% Clean c o o r d i n a t e s v a l u e s
c o o r d s a D i s k ( i , j , 2 ) = mod ( c o o r d s a D i s k ( i , j , 2 ) , 2 ∗ p i ) ;
i f coords aDisk ( i , j ,2) > pi
c o o r d s a D i s k ( i , j , 2 ) = 2∗ p i − c o o r d s a D i s k ( i , j , 2 ) ;
end
%c o o r d s a D i s k ( i , j , 2 )
11
Final Project – MATH 599 R. Raquépas and E. Schulz
%r o u n d ( c o o r d s a D i s k ( i , j , 2 ) ∗ ( ( a c c r e t i o n s c e n e w i d t h r e s −1)/(2∗ p i ) ) + 1 )
i f c o o r d s n o a D i s k ( i , j , 3 ) == 1
IMG( i , j , : ) = a c c r e t i o n d i s k s c e n e ( r o u n d ( ( c o o r d s a D i s k ( i , j ,1)− aDiskMin ) ∗ ( ( a c c r e t i o n s c e n e h e i g h t r e s −1)/( aDiskMax − aDiskMin ) ) + 1 ) , . . .
r o u n d ( c o o r d s a D i s k ( i , j , 2 ) ∗ ( ( a c c r e t i o n s c e n e w i d t h r e s −1)/(2∗ p i ) ) + 1 ) , : ) ;
else
end
boolean aDisk = 0;
end
end
end
i f b o o l e a n a D i s k == 1
i f c o o r d s n o a D i s k ( i , j , 3 ) == 1
IMG( i , j , 1 ) = 0 ;
IMG( i , j , 2 ) = 0 ;
IMG( i , j , 3 ) = 0 ;
else
IMG( i , j , : ) = c e l e s t i a l s c e n e ( r o u n d ( c o o r d s n o a D i s k ( i , j , 1 ) ∗ ( ( c e l e s t i a l s c e n e h e i g h t r e s −1)/ p i ) + 1 ) , . . .
r o u n d ( c o o r d s n o a D i s k ( i , j , 2 ) ∗ ( ( c e l e s t i a l s c e n e w i d t h r e s −1)/(2∗ p i ) ) + 1 ) , : ) ;
end
end
boolean aDisk = 1;
end
end
switch k
case 1
i m w r i t e ( IMG, ’ g r i d ’ , ’ j p g ’ )
case 2
i m w r i t e ( IMG, ’ t e s t 2 I n t e r s t e l l a r W o r m h o l e F i g 6 B H d i s k . j p g ’ , ’ j p g ’ )
case 3
i m w r i t e ( IMG, ’ t e s t 2 I n t e r s t e l l a r W o r m h o l e F i g 1 0 B H d i s k . j p g ’ , ’ j p g ’ )
end
%F i n a l c o m p u t a t i o n s t i m e
tEnd = t o c ( t S t a r t ) ;
f p r i n t f ( ’% d m i n u t e s and %f s e c o n d s\n ’ , f l o o r ( t E n d / 6 0 ) , rem ( tEnd , 6 0 ) ) ;
12