Created
August 28, 2013 21:19
-
-
Save MercuryRising/6371447 to your computer and use it in GitHub Desktop.
Hypocycloid Gravity Train
This file contains 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
# -*- coding: utf-8 -*- | |
from math import * | |
import wolframalpha | |
client = wolframalpha.Client("YHQ3GK-PT45KT9AHG") | |
radius = 6367500 | |
circumference = 2*pi*radius | |
gravitational_constant = 9.8 # m/s2 | |
def cycloid_length(surface_distance): | |
''' Returns kilometer length of hypocycloid over surface_distance''' | |
length = 2*surface_distance*(2*pi*radius-surface_distance)/(pi**2*radius) | |
return int(length//1000) | |
def cycloid_time(surface_distance, humanize=True): | |
''' Returns seconds of travel time, or humanized representation of time''' | |
travel_time = sqrt(surface_distance*(2*pi*radius-surface_distance)/(radius*gravitational_constant)) | |
if humanize: | |
return humanize_time(travel_time) | |
return travel_time | |
def cycloid_maximum_velocity(surface_distance): | |
''' Returns the maximum velocity that will be attained | |
This velocity is reached at the bottom of the hypocycloid | |
''' | |
return sqrt(gravitational_constant*surface_distance*(2*pi*radius-surface_distance)/radius)/pi | |
def humanize_time(inseconds): | |
hours = inseconds//3600 | |
minutes = (inseconds//60)%60 | |
seconds = inseconds%60 | |
hours, minutes, seconds = map(lambda x: str(int(x)).zfill(2), (hours, minutes, seconds)) | |
return "%s:%s.%s"%(hours, minutes, seconds) | |
def determine_city_transit(cityA, cityB): | |
query = "distance between city {0} and city {1} in km".format(cityA, cityB) | |
result = client.query(query).results | |
for r in result: | |
surface_distance = float(r.text.split(" ")[0])*1000 | |
print "Surface distance between %s and %s: %s" %(cityA, cityB, r.text) | |
if surface_distance: | |
print "Cycloid length between cities: %.2f km" %(cycloid_length(surface_distance)) | |
print "Travel time between cities: %s" %(cycloid_time(surface_distance)) | |
print "Maximum velocity: %.2f m/s" %(cycloid_maximum_velocity(surface_distance)) | |
def determine_transit(surface_distance): | |
surface_distance = surface_distance | |
print "Cycloid length for %s km of surface: %.2f km" %(surface_distance, cycloid_length(surface_distance)) | |
print "Travel time: %s" %(cycloid_time(surface_distance)) | |
print "Maximum velocity: %.2f m/s" %(cycloid_maximum_velocity(surface_distance)) | |
cityA = "London" | |
cityB = "New York" | |
determine_city_transit(cityA, cityB) | |
#determine_transit(pi*radius) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment