Skip to content

Instantly share code, notes, and snippets.

@armhold
Created April 28, 2016 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armhold/f19309144dbfb91bf2c0a9d6ce16d1fa to your computer and use it in GitHub Desktop.
Save armhold/f19309144dbfb91bf2c0a9d6ce16d1fa to your computer and use it in GitHub Desktop.
relativistic distance calculator
// 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