Zum Inhalt springen

Datei:Lorentz Transform Animation.gif

Aus MOOCsWiki Staging
Originaldatei (256 × 256 Pixel, Dateigröße: 232 KB, MIME-Typ: image/gif, Endlosschleife, 128 Bilder, 7,7 s)

Diese Datei stammt aus Wikimedia Commons und kann von anderen Projekten verwendet werden. Die Beschreibung von deren Dateibeschreibungsseite wird unten angezeigt.

Beschreibung

Beschreibung
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.
Datum
Quelle Eigenes Werk
Urheber Drummyfish
GIF‑Erstellung
InfoField
 Diese GIF-Rastergrafik wurde mit Python erstellt.
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

Lizenz

Ich, der Urheber dieses Werkes, veröffentliche es unter der folgenden Lizenz:
Creative Commons CC-Zero Diese Datei wird unter der Creative-Commons-Lizenz CC0 1.0 Verzicht auf das Copyright zur Verfügung gestellt.
Die Person, die das Werk mit diesem Dokument verbunden hat, übergibt dieses weltweit der Gemeinfreiheit, indem sie alle Urheberrechte und damit verbundenen weiteren Rechte – im Rahmen der jeweils geltenden gesetzlichen Bestimmungen – aufgibt. Das Werk kann – selbst für kommerzielle Zwecke – kopiert, modifiziert und weiterverteilt werden, ohne hierfür um Erlaubnis bitten zu müssen.

Kurzbeschreibungen

Ergänze eine einzeilige Erklärung, was diese Datei darstellt.
animation showing the Lorentz transformation used in theory of relativity

In dieser Datei abgebildete Objekte

Motiv

237.548 Byte

7,67999999999998 Sekunde

256 Pixel

256 Pixel

image/gif

6af32fa49b99309fae190839bb56cfec249ae590

Dateiversionen

Klicke auf einen Zeitpunkt, um diese Version zu laden.

Version vomVorschaubildMaßeBenutzerKommentar
aktuell21:34, 1. Apr. 2019Vorschaubild der Version vom 21:34, 1. Apr. 2019256 × 256 (232 KB)wikimediacommons>DrummyfishGeneral improvement

Die folgende Seite verwendet diese Datei:

Metadaten