Last active
August 29, 2015 14:16
-
-
Save saulshanabrook/f8a96b7c0f7179253f1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from visual import * | |
c = 3e08 | |
v = vector(0.5*c, 0, 0.9*c) | |
t = 0 | |
dt = 1e-9 | |
gamma_x = 1/sqrt(1 - (v.x/c)**2) | |
gamma_y = 1/sqrt(1 - (v.y/c)**2) | |
gamma_z = 1/sqrt(1 - (v.z/c)**2) | |
#function to increase resolution of shape from ints to floats from http://stackoverflow.com/a/477610 | |
def drange(start, stop, step): | |
r = start | |
while r < stop: | |
yield r | |
r += step | |
#function to change color of moving objects (here: points) | |
def doppler_shift(v): | |
beta = v/c | |
freq_ratio_approach = sqrt((1 - beta)/(1 + beta)) | |
freq_ratio_recede = sqrt((1 + beta)/(1 - beta)) | |
if v > 0: | |
return (freq_ratio_approach, 0, 1) | |
else: | |
return (1, 0, freq_ratio_recede) | |
#function to transform position of points | |
def lorentz_trans(v, x, t): | |
gamma_x = 1/sqrt(1 - (v.x/c)**2) | |
x_prime = gamma_x * (x.x - v.x*t) | |
return x_prime | |
# ok so first we are gonna build up a list of all the initial points in a list of vectors | |
original_points = [] | |
# to make some initial points for a circle, iterate `i` through a bunch of numbers | |
for i in drange(-10, 10, 0.05): | |
x1 = i | |
y1 = (100.0 - i**2)**(1.0/2) | |
y2 = -(100.0 - i**2)**(1.0/2) | |
z = 0 | |
original_points.append(vector(x1, y1, z)) | |
# original_points.append(vector(x1, y2, z)) | |
#plot the original points in mauve and moving points in a shifted color | |
points(pos = original_points, size = 2, color = (1, 0, 1)) | |
for pt in original_points: | |
pt.x = gamma_x * pt.x | |
moving_pts = points(pos = original_points, color = doppler_shift(v.z), size = 2) | |
# now we are going through a big range, and for each value in it, we are moving the the pts by `v*dt` | |
for _ in range(100000): | |
moving_pts.pos += v*dt | |
rate(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment