#!/usr/bin/perl
#
# Generate some data illustrating Galilean and Lorentz transformations.
#
# MWR 9/19/2008

$debug = 1;


###########
#  following is ordinary galilean transform
if (0 == 1) {

# speed (m/s) of object being observed by two observers
$object_speed = 2.0;
$init_x = 3.0;


# Galilean transform
#      x' = x + g_dx
#      t' = t + g_dt
#
$g_dx = 5;
$g_dt = 0;

$start_t = 0.0;
$end_t = 20.0;
$d_t = 1.0;

for ($t = $start_t; $t <= $end_t; $t += $d_t) {

  $x = $init_x + $t*$speed;

  $x_prime = $x + $g_dx;
  $t_prime = $t + $g_dt;

  printf "  t %9.2f x %9.2f   t' %9.2f x' %9.2f \n",
           $t, $x, $t_prime, $x_prime;
}


}
###### end of Galilean transform



###########
#  following is Lorentz transform
if (1 == 1) {

# speed (in terms of C) of object being observed by two observers
$object_speed = 0.5;
$init_x = 3.0;

# speed of the primed reference frame relative to normal frame
$frame_speed = 0.2;
$gamma = 1.0 / sqrt(1.0 - $frame_speed*$frame_speed);


# Lorentz transform
#      x' = x + g_dx
#      t' = t + g_dt
#
$g_dx = 5;
$g_dt = 0;

$start_t = 0.0;
$end_t = 20.0;
$d_t = 1.0;

for ($t = $start_t; $t <= $end_t; $t += $d_t) {

  $x = $init_x + $t*$object_speed;

  $x_prime = $gamma*($x - $frame_speed*$t);
  $t_prime = $gamma*( ($t - $frame_speed*$x) );

  printf "  t %9.2f x %9.2f   t' %9.2f x' %9.2f \n",
           $t, $x, $t_prime, $x_prime;
}


}
###### end of Galilean transform










exit 0;
