lundi 25 juillet 2016

Simulating a logarithmic spiral galaxy in python

I am simulating a logarithmic spiral galaxy using python. Using the parametric equations,

x= a*exp(b*theta)*cos(theta) and y= a*exp(b*theta)*sin(theta)

I used numpy.random for getting the random distribution of stars. The sample code is given below.

import random
from math import *
from pylab import *
import numpy as np

n=100000
a= 1
b=0.6
th =np.random.randn(n)
x= a*exp(b*th)*cos(th)
y=a*exp(b*th)*sin(th)
x1 = a*exp(b*(th))*cos(th+ pi)
y1=a*exp(b*(th))*sin(th + pi)
plot(x,y,"*")
plot(x1, y1,"*")
show()

The resulting image is shown below spiral galaxy with two arms

What I need: 1) stars should be radially distributed in the spiral galaxy. I got the distribution only along the arms. 2) Both arms should be blue. Here I have one arm with blue color and other with green.

After simulating this, I need to rotate the galaxy. Any help regarding this would be appreciable.




Aucun commentaire:

Enregistrer un commentaire