Created
April 28, 2016 16:15
-
-
Save armhold/f19309144dbfb91bf2c0a9d6ce16d1fa to your computer and use it in GitHub Desktop.
relativistic distance calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// quick back of envelope calculations for computing distance traveled (from traveler's perspective) | |
// when constantly accelerating at 9.8 m/s^2. | |
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
const ( | |
C = 2.998e+8 // meters per second | |
SecondsPerYear = 60.0 * 60.0 * 24.0 * 365.0 | |
MetersPerLightYear = 9.4607e+15 | |
a = 9.80665 | |
) | |
func main() { | |
yearsTraveling := 6.75 | |
distInMeters := relativisticDistance(SecondsPerYear * yearsTraveling) | |
distInLightYears := distInMeters / MetersPerLightYear | |
fmt.Printf("distance in meters: %f\n", distInMeters) | |
fmt.Printf("distance in light years: %f\n", distInLightYears) | |
} | |
// https://en.wikipedia.org/wiki/Space_travel_using_constant_acceleration#Expressions_for_covered_distance_and_elapsed_time | |
func relativisticDistance(timeInSeconds float64) float64 { | |
return C * C / a * (math.Cosh((a*timeInSeconds)/C) - 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment