Travel Time to Alpha Centauri - Python Program

in #steemstem6 years ago (edited)

Travel Time to Alpha Centauri - In Python

alpha_cen.JPG
The star Alpha Centauri. Image Credit: Author

After reading @procrastilearner's article Kill Time At Work With Recreational Math: Let's Travel To Alpha Centauri! I decided to have an attempt at coding his excel sheet to calculate travel time to Alpha Centauri in Python (which I am very new at).

To quickly recap, the original problem was to calculate the travel time it would take to travel to Alpha Centauri. By travel time, I mean the time experienced by the travelers. We will also assume that the spacecraft has the ability to maintain an acceleration/deceleration of 1G for the entire journey.

As it turns out this program (listed below) does indeed give the expected answer of 3.6 years. Incidentally, for observers on earth, the journey would take 6 years. This is the effect of time dilation due to Special Relativity.

screenshot.png

For reference here are @procrastilearner’s articles.

And here is the code.

# Compute ship travel time to Alpha Centauri based on constant 1g acceleration and deceleration

import math

# Convert meters to light years
def m2ly(m):
    return(m/9454254955488000.0)

# Convert seconds to years
def sec2year(sec):
    return(sec/(3600*24*365.25))

# velocity in ms
def lorenzfactor(v):
    c = 299792458.0
    return(1 / math.sqrt(1 - (v * v) / (c * c)))

# velocity in ms
def compositionofvelocities(u_,v):
    c = 299792458.0
    return((u_+v)/(1 + u_*v/(c*c)))

counter = 1
ts = 0
ts_incr = 1000.0

# initial distance travelled of ship
d = 0.0

# initial velocity of ship
v1 = 0.0

# initial time of ship
t_s = 0.0

# target distance in m (half distance to Alpha Centauri
d_target = 2.15 * 9454254955488000.0

while (d < d_target):
    counter = counter + 1
# compute lorentz factor for current velocity
    lorentz = lorenzfactor(v1)
# increment earth time
    ts_previous = ts
    ts = ts + ts_incr
# increment ship time
    t_s = t_s + ts_incr / lorentz
    a = 9.8 / lorentz
# velocity increment
    v2 = a * ts_incr
# New velocity based on composition of velocities
    v1_previous = v1
    v1 = compositionofvelocities(v1,v2)

# Compute new distance
    d = d + 0.5 * (v1_previous + v1) * (ts - ts_previous)

# Final time and distance (time to accelerate and to deccelerate
print("Time taken ="+str(2*sec2year(t_s))+" years")
Sort:  

With acceleration/deceleration of 1G is there a top speed reached? Speed of light? And incredible that the relative time passed on Earth is 166% more time passed.

I calculate 0.95 times the speed of light. What is actually even more interesting is that it doesn't take much more time to cover a lot more distance. To reach a thousand light years would take 13 years ship time, but back on earth just over a 1000 years will have passed, and by the time you got a signal back to earth yet another 1000 years will have passed.

That is really amazing, how time is so relative to your situation.

It is basically relative to speed and gravity! The higher the speed at which an object moves or the more powerful the gravitational field an object suffers from, the slower time flows as observed by this specific object.

Great answer, thank you!

Funnily enough, I cannot resist from advertising one of my old articles where I showed that it was possible to reach the end of the observable universe and come back in less than a human lifetime even with a constant acceleration of 1g. See here. I hope you will enjoy it :D

I just recently did a piece similar to yours, well, if you minus the fact that mine was not as articulate, not only speaking of the mathematical equations, but showing the work too! Haha, it was a great read for sure. Much more in depth than I took it and very well explained so someone who enjoys physics or fishing could retain and understand what you explained. @terrylovejoy has been a great Mentor so far for me. Steemstem seems to have a very meticulous and fine tuned team I will say that. Ive only known terry for a short time and he has helped me improve in great strides so I too can produce the quality this group is expected to publish. Cheers.

I just read your post. Indeed, including a bit more structure on it could have been useful (it is kind of pretty hard to read, to be honest). However, you have really improved with your last one on the gravitational wave :)

Thank you so much for the compliment @lemouth. I've never been one to writr, clearly, until now and @terrylovejoy has been a tremendous help. If I do something I really try to do it my best. Some things just take practice. 👍🏻

However, please don't ask me to work for you! This is not how it works around here...

😂 noted sir.

Thank you for the complement's @param3dic , that means a lot!

That's brilliant, you've also included the analytical method for calculating this in the post (rather than the brute force method above). The sad thing is that there would be probably nothing to come back to from that journey :(

Totally, although as I said it in my post, it is not clear we will be able to ever accomplish it as we are missing the technology so far.

Yeah, nothing we can fathom can actually travel faster than speed of light. The calculations based on a trip traveling at 1 G accelerating first half of the flight and decelerating the second half is what they are seeming to see as the sweet spot. When you get into time dilation due to special relativity it is just mind boggling. With the exception of a few close places, any were else is a one way ticket bc the amount of time passed here means Earth could be destroyed of at the very least humanity. And the crazy thing is most people do not thing about there is a difference between interstellar and intergalactic travel. If we actually were to travel intergalactic at 1G to the closest galaxy to us, Andromeda, it would take 60 years about the craft and 5,000,000 years will have passed on Earth. So you either set off as nomads really vs explorers. Until there is something unbelievably radical discovered, such as how to not only make a worm hole, but control the start and finish to where you want to go. Then you are talking more like stepping through a doorway bc you have literally folded space-time in half. It’s truely mezmoring when thinking about things like this. The flip side is its almost disheartening and really makes it feel as though we are not meant to go beyond our playground. Sorry for the massive ramble session! :)

On the contrary, we like people who constantly ask questions. It's the path to our future :P
Thanks for sharing!

I certainly agree! Thanks for the read

This is great. I'm going to install Python once again and test it out for sure.

Now all we need to do is learn how to bottle a few grams of anti-matter.

Hey @terrylovejoy, thank you for providing code. Python is indeed a great and simple tool.

It truly is mind blowing how time slows down the faster we move, especially in such high speeds time dilation is rather significant.

Thank you for your contributions!

I cannot resist and advertise this link here. I am sure you will enjoy it (it has extra cool features compared to your code)! ;)

Hey that is really cool...thanks for that!

My pleasure!

Thanks for the link. I am going to add it as a reference in my post as well.

My pleasure! (yeah I know, twice the same comment in the same post :p ).

9D1BE482-60E0-4925-A1D4-58BC8807E54D.jpeg

Excellent stuff - most people don't understand time dilation when travelling close to light speed - your calculation would cover pretty much any distance you want to travel. When i did the sums 30 years ago i got 2 years at 1g to be near light velocity and as the journey time is then negligible, 2 years to slow down. As the relative journey time remains the same, i would opt for Proxima Centauri to look at the possible habitable planets. :)

The problem with Proxima Centauri is it flares regularly, one was recently recorded that increased the star's output by nearly 100 times that lasted a few minutes. It would be hard to imagine a planet around a star like that sustaining life, unless it was underground.

What is the 1G speed? I am a big fan of some science fiction things. I love Star Trek and Star Wars and the X-Files. I do like learning things. I'm Oatmeal. Thanks for sharing.

1G = acceleration of 9.8 meters per second, per second. That is the acceleration that mimics the effect of earth's gravity on our body and is therefore comfortable for us.

Interesting. Thanks.

Nice way to stitch together space and programming. I am still looking for ways to do that. You could add a graphical representation as well, I don't know Python all that well myself though. But it's very similar to C++ from what I can tell. When I was younger I experimented with Flash and ActionScript as it would be able to create very good visual representations and animations. I was just playing with Adobe Animate yesterday, which is basically Flash with more tools. I am thinking of eventually creating video articles, or at least video infographics to accompany my articles.

There are definitely plenty of ways of stitching space and programming together. Actually, for comet searching I use a who lot of programming, mainly C#, for image acquisition, processing and detection. Any way thanks for dropping by @alexdory !

You could supply your code as opensource projects on github and post them in utopian-io.
Biggest account on Steemit. A fast growing terrylovejoy is good for all the communities in which he operates :)

So cool (for a geek like me)

Thanks for dropping by @intrepidphotos , glad you liked it!

Nice exercise :)

Coin Marketplace

STEEM 0.18
TRX 0.13
JST 0.028
BTC 57296.76
ETH 3055.75
USDT 1.00
SBD 2.32