#!/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
$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 for x-axis
if (0 == 1) {

# speed (in terms of C) of object being observed by two observers
$speed = 0.5;
$init_x = 3.0;
$gamma = 1.0 / sqrt(1.0 - $speed*$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;

# this is the x-axis
$t = 0;
for ($x = 0; $x < 100; $x++) {
  
  $x_prime = $gamma*($x);
  $t_prime = $gamma*($t + $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





###########
#  following is Lorentz transform for t-axis
if (1 == 1) {

# speed (in terms of C) of object being observed by two observers
$speed = 0.5;
$init_x = 3.0;
$gamma = 1.0 / sqrt(1.0 - $speed*$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;

# this is the t-axis
$x = 0;
for ($t = 0; $t < 100; $t++) {
  
  $x_prime = $gamma*($x + $speed*$t);
  $t_prime = $gamma*($t + $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;
