Vpython program about relativity.

[ad_1]
Write a space ship simulation to observe the “Twin Paradox.” Treat each time step
using Special Relativity. The ship should be controlled using keys, keeping track of
Earth-time and on-board time.More info in files.Framework as follow:from visual import *
# The timestep length in Earth frame(might need to be adjusted)
dt=0.01
# The rate
dtrate=100
# The velocity change
dv=0.05
# The beta values
bx=0.0
by=0.0
beta=0.0
# Speed limit
maxbeta=0.9999
# Drag (if desired)
drag=0.9999;
# Time on Earth and in the Ship
tearth=0.0
tship=0.0
#
# ========================================================
# ========================================================
#
# Listen for keys
# Modify this for interactions
#
def listenkeys():
global bx,by,beta,maxbeta,dv
# Was a key pressed?
if scene.kb.keys:
# Yes, which one?
s=scene.kb.getkey()
# This is where you have to add all your keys
# “x” exits
if s==’x’:
exit()
# Deal with the velocity keys to modify bx, by
# …
# Enforce maximum speed
# …
# Calculate beta
#
# The routine that displays your values
# Just for demo
def displayvalues():
global beta,tearth,tship
betalabel.text=”Beta: %.4f” % beta
earthtime.text=”Earth: %.4f” % tearth
shiptime.text=”Ship: %.4f” % tship
# Move the ship
def moveship():
global bx,by,dt,drag,beta
# Move the ship
# …
# Apply drag
# …
# Recalculate beta after drag
# …
# ========================================================
# Main program
# Setting up things
# Make the Earth
earth=sphere(pos=(0,0,0),radius=1.2,color=color.blue);
# Make some stars to look cute
sphere(pos=(5,2,0),radius=0.1,color=color.white);
sphere(pos=(-5,3,0),radius=0.1,color=color.white);
sphere(pos=(5,-5,0),radius=0.1,color=color.white);
sphere(pos=(2,7,0),radius=0.1,color=color.white);
sphere(pos=(3,2,0),radius=0.1,color=color.white);
sphere(pos=(-3,-4,0),radius=0.1,color=color.white);
# Make the ship
ship=sphere(pos=(1.2,0,0),radius=0.2,color=color.red);
# Make the beta label
betalabel=label(pos=(-6.5,6.5,0),text=””,xoffset=1,line = 0)
earthtime=label(pos=(-6.5,5.5,0),text=””,xoffset=1,line = 0)
shiptime=label(pos=(-6.5,4.5,0),text=””,xoffset=1,line = 0)
# Keep the scene from expanding
scene.autoscale=False
# Infinite loop
while True:
rate(dtrate)
listenkeys()
displayvalues()
moveship()
# Calculate time in Earth frame and Ship frame
# …
[ad_2]Source link
 
“Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!”

What Students Are Saying About Us

.......... Customer ID: 12*** | Rating: ⭐⭐⭐⭐⭐
"Honestly, I was afraid to send my paper to you, but splendidwritings.com proved they are a trustworthy service. My essay was done in less than a day, and I received a brilliant piece. I didn’t even believe it was my essay at first 🙂 Great job, thank you!"

.......... Customer ID: 14***| Rating: ⭐⭐⭐⭐⭐
"The company has some nice prices and good content. I ordered a term paper here and got a very good one. I'll keep ordering from this website."

"Order a Custom Paper on Similar Assignment! No Plagiarism! Enjoy 20% Discount"