<?PHP
/*
In this example, we use $v to represent velocity and $t to represent time. Each value is converted to seconds
to be compared against the speed of light in seconds.
*/
include('time_dilation.class.php');
$tdil = new time_dilation;
if( !empty($_REQUEST['formSubmitted']) ){
$velocity = ( empty($_REQUEST['velocity']) ) ? 0 : $_REQUEST['velocity'];
$unit = $_REQUEST['unit'];
$timeFrame = $_REQUEST['timeFrame'];
$years = ( empty($_REQUEST['years']) ) ? 0 : $_REQUEST['years'];
$months = ( empty($_REQUEST['months']) ) ? 0 : $_REQUEST['months'];
$days = ( empty($_REQUEST['days']) ) ? 0 : $_REQUEST['days'];
$hours = ( empty($_REQUEST['hours']) ) ? 0 : $_REQUEST['hours'];
$minutes = ( empty($_REQUEST['minutes']) ) ? 0 : $_REQUEST['minutes'];
$seconds = ( empty($_REQUEST['seconds']) ) ? 0 : $_REQUEST['seconds'];
$percLight = ( empty($_REQUEST['percLight']) ) ? 0 : $_REQUEST['percLight'];
if( $unit == 'metric' ){
$tdil->setSpeedOfLight('metric');
}elseif( $unit == 'usa' ){
$tdil->setSpeedOfLight('usa');
}
switch( $_REQUEST['timeSelect'] ){
case 'veryNearLight':
$v = $tdil->speedOfLight*.999999999;
break;
case 'percLight':
$v = $tdil->speedOfLight*($percLight/100);
break;
default:
$v = $tdil->velocityToSec($velocity,$timeFrame);
}
$t = $tdil->timeToSec($seconds,$minutes,$hours,$days,$months,$years);
switch( $_REQUEST['observer'] ){
case 'stationary':
$astro = $tdil->secToTime($t);
$earth = $tdil->dilation($t,$v,'stationary');
break;
case 'moving':
$earth = $tdil->secToTime($t);
$astro = $tdil->dilation($t,$v);
break;
}
}else{
$_REQUEST['timeSelect'] = 'percLight';
$_REQUEST['observer'] = 'moving';
}
?>
<html>
<head>
<title>Time Dilation Example</title>
<style>
a {
color: black;
text-decoration: none;
}
a:hover {
color: red;
}
</style>
</head>
<body>
<p>This example uses the classic scenario where two twins are in the space program. One is an astronaut and takes off from earth in a spaceship while the other stays on earth to monitor his progress. The faster the astronaut travels, the larger the spread will be between their ages.</p>
<form method="post">
<h4>Velocity</h4>
<div>
Astronaut will be traveling...
<div style="margin-top:10px;">
<input type="radio" name="timeSelect" value="percLight"<?PHP echo ( $_REQUEST['timeSelect'] == 'percLight' ) ? ' checked' : '';?>> at <input type="text" name="percLight" value="<?PHP echo ( !empty($_REQUEST['percLight']) ) ? $_REQUEST['percLight'] : '';?>" size="4"> precent of light speed
</div>
<div style="margin-top:10px;">
<input type="radio" name="timeSelect" value="veryNearLight"<?PHP echo ( $_REQUEST['timeSelect'] == 'veryNearLight' ) ? ' checked' : '';?>> very near light speed
</div>
<div style="margin-top:10px;">
<input type="radio" name="timeSelect" value="custom"<?PHP echo ( $_REQUEST['timeSelect'] == 'custom' ) ? ' checked' : '';?>> at a rate of <input type="text" name="velocity" value="<?PHP echo ( !empty($_REQUEST['velocity']) ) ? $_REQUEST['velocity'] : '';?>" size="6">
<select name="unit">
<option value="usa"<?PHP echo ( !empty($_REQUEST['unit']) AND $_REQUEST['unit'] == 'usa' ) ? ' selected' : '';?>>miles</option>
<option value="metric"<?PHP echo ( !empty($_REQUEST['unit']) AND $_REQUEST['unit'] == 'metric' ) ? ' selected' : '';?>>kilometres</option>
</select>
<select name="timeFrame">
<option value="second"<?PHP echo ( !empty($_REQUEST['timeFrame']) AND $_REQUEST['timeFrame'] == 'second' ) ? ' selected' : '';?>>per Second</option>
<option value="minute"<?PHP echo ( !empty($_REQUEST['timeFrame']) AND $_REQUEST['timeFrame'] == 'minute' ) ? ' selected' : '';?>>per Minute</option>
<option value="hour"<?PHP echo ( !empty($_REQUEST['timeFrame']) AND $_REQUEST['timeFrame'] == 'hour' ) ? ' selected' : '';?>>per Hour</option>
</select>
<div>
</div>
<h4>Time</h4>
<div>
Astronaut will be traveling for...<br>
<input type="text" name="years" size="4" value="<?PHP echo ( !empty($_REQUEST['years']) ) ? $_REQUEST['years'] : '';?>"> Year(s)<br>
<input type="text" name="months" size="4" value="<?PHP echo ( !empty($_REQUEST['months']) ) ? $_REQUEST['months'] : '';?>"> Month(s)<br>
<input type="text" name="days" size="4" value="<?PHP echo ( !empty($_REQUEST['days']) ) ? $_REQUEST['days'] : '';?>"> Day(s)<br>
<input type="text" name="hours" size="4" value="<?PHP echo ( !empty($_REQUEST['hours']) ) ? $_REQUEST['hours'] : '';?>"> Hour(s)<br>
<input type="text" name="minutes" size="4" value="<?PHP echo ( !empty($_REQUEST['minutes']) ) ? $_REQUEST['minutes'] : '';?>"> Minute(s)<br>
<input type="text" name="seconds" size="4" value="<?PHP echo ( !empty($_REQUEST['seconds']) ) ? $_REQUEST['seconds'] : '';?>"> Second(s)<br>
</div>
<h4>Observer</h4>
<div>
As observed by the...<br>
<input type="radio" name="observer" value="moving"<?PHP echo ( $_REQUEST['observer'] == 'moving' ) ? ' checked' : '';?>> Astronaut<br>
<input type="radio" name="observer" value="stationary"<?PHP echo ( $_REQUEST['observer'] == 'stationary' ) ? ' checked' : '';?>> Earth<br>
</div>
<div style="margin-top:20px;">
<input type="hidden" name="formSubmitted" value="1">
<input type="submit" name="submitForm" value="Calculate">
[<a href="example.php">start over</a>]
</div>
</form>
<?PHP
if( !empty($astro) ){
?>
<div style="margin-top:20px;">
Astronaut traveled for <?PHP echo $earth['years'];?> years, <?PHP echo $earth['months'];?> months, <?PHP echo $earth['days'];?> days, <?PHP echo $earth['hours'];?> hours, <?PHP echo $earth['minutes'];?> minutes, <?PHP echo $earth['seconds'];?> seconds and <?PHP echo $earth['remainder'];?> of a second
</div>
<div style="margin-top:10px;">
The time passed on earth is <?PHP echo $astro['years'];?> years, <?PHP echo $astro['months'];?> months, <?PHP echo $astro['days'];?> days, <?PHP echo $astro['hours'];?> hours, <?PHP echo $astro['minutes'];?> minutes, <?PHP echo $astro['seconds'];?> seconds and <?PHP echo $astro['remainder'];?> of a second
</div>
<?PHP
}
?>
</body>
</html>
|