File:Lorentz Transform Animation.gif
Lorentz_Transform_Animation.gif (256 × 256 pixels, file size: 232 KB, MIME type: image/gif, looped, 128 frames, 7.7 s)
Captions
Summary[edit]
DescriptionLorentz Transform Animation.gif |
English: This file recreates this file, except this one is free of copyright restrictions. I created it myself by writing an own script in Python, and I release it under CC0.
The animation shows the effect of Lorentz transform used in theory of relativity. An observer moving along a world line (red) is shown along with random events in space-time (black dots). The diagonal grey lines indicate the speed of light. Compare this to Galilean transform. |
Date | |
Source | Own work |
Author | Drummyfish |
Source code InfoField | # space transformation animation in Python
# by Drummyfish
# released under CC0 1.0
from PIL import Image
import random
import math
TRANSFORM_TYPE = 0 # 0 = galileian, 1 = lorentz
SPEED_OF_LIGHT = 1
SIZE = 256
TRAJECTORY = (
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l \n"
" l "
)
TRAJECTORY_POINTS = [(i.find("l") - 20) * 0.5 for i in TRAJECTORY.split("\n")]
TRAJECTORY_POINTS.reverse()
random.seed(35)
EVENTS = [(random.randrange(SIZE * 40) - 20 * SIZE,random.randrange(len(TRAJECTORY_POINTS))) for i in range(500)]
def draw_square(pixels, x, y, r, c):
x -= r / 2
y -= r / 2
x2 = x + r
y2 = y + r
x = max(0,x)
y = max(0,y)
x2 = min(SIZE - 1,x2)
y2 = min(SIZE - 1,y2)
for j in range(y,y2):
for i in range(x,x2):
pixels[i,j] = c
def transform_galilean(relative, velocity):
return (int(relative[0] - velocity * relative[1]),relative[1])
def transform_lorentz(relative, velocity):
sol2 = SPEED_OF_LIGHT * SPEED_OF_LIGHT
factor = 1.0 / math.sqrt(1.0 - velocity * velocity / sol2)
return (int(factor * (relative[0] - velocity * relative[1])),
int(factor * (relative[1] - (velocity * relative[0]) / sol2)))
def draw_event(relative_event, velocity, pixels, color, size):
transformed = transform_galilean(relative_event,velocity) if TRANSFORM_TYPE == 0 else transform_lorentz(relative_event,velocity)
screen = (SIZE / 2 + transformed[0],SIZE / 2 - transformed[1])
draw_square(pixels,screen[0],screen[1],size,color)
image = Image.new("RGB",(SIZE,SIZE),"white")
pixels = image.load()
v_previous = 0
for f in range(len(TRAJECTORY_POINTS)): # for each frame
for j in range(SIZE): # clear the canvas
for i in range(SIZE):
relative_y = SIZE / 2 - j
helper_line = (relative_y == 0) or (relative_y % 32 == 0 and i % 4 == 0)
if TRANSFORM_TYPE == 1:
relative_x = SIZE / 2 - i
if abs(relative_x / float(relative_y if relative_y != 0 else 0.0001)) == SPEED_OF_LIGHT:
helper_line = True
pixels[i,j] = (200,200,200) if helper_line else (255,255,255)
x = TRAJECTORY_POINTS[f]
# compute average velocity over several trajectory points, for smooth movement:
avg = 10
weight_sum = 0
v = 0
for n in range(avg):
index = f - n + avg / 2
weight = avg / 2 - abs(avg / 2 - n) + 1
v += weight * (TRAJECTORY_POINTS[(index + 1) % len(TRAJECTORY_POINTS)] - TRAJECTORY_POINTS[index % len(TRAJECTORY_POINTS)])
weight_sum += weight
v = v / float(weight_sum)
v = (v + v_previous) / 2.0 # this smooths acceleration
v_previous = v
for k in range(-2,3): # draw events
for e in EVENTS:
relative = (e[0] - x,e[1] - f + k * len(TRAJECTORY_POINTS))
draw_event(relative,v,pixels,(0,0,0),3)
for n in range(SIZE): # draw the trajectory
index = n - SIZE / 2
trajectory_index = (f + index) % len(TRAJECTORY_POINTS)
relative = (TRAJECTORY_POINTS[trajectory_index] - x, index)
draw_event(relative,v,pixels,(255,0,0),2)
draw_square(pixels,SIZE / 2,SIZE / 2,7,(0,0,255)) # draw the observer
image.save("out" + str(f).zfill(4) + ".png") # save the frame
|
Licensing[edit]
This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication. | |
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse |
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 19:34, 1 April 2019 | 256 × 256 (232 KB) | Drummyfish (talk | contribs) | General improvement | |
18:10, 31 March 2019 | 256 × 256 (159 KB) | Drummyfish (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
The following page uses this file:
File usage on other wikis
The following other wikis use this file:
- Usage on azb.wikipedia.org
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
GIF file comment | created with GIMP by Drummyfish, released under CC0 |
---|