File:Lorentz Transform Animation.gif

Summary

Description
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
 
This GIF graphic was created with Python.
Category:PNG created with Python#Lorentz%20Transform%20Animation.gif
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

I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero 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.

Category:CC-Zero#Lorentz%20Transform%20Animation.gif
Category:Self-published work Category:Lorentz boosts Category:Animations of geometry Category:Animations of theory of relativity Category:Animated GIF files Category:Animations of special relativity Category:Images with Python source code
Category:Animated GIF files Category:Animations of geometry Category:Animations of special relativity Category:Animations of theory of relativity Category:CC-Zero Category:Images with Python source code Category:Lorentz boosts Category:PNG created with Python Category:Pages using deprecated source tags Category:Self-published work