Question: This is the code from previous class. Without using threshold values, answer 1 and elaborate on result from 1 to code 2 using energy principles.

This is the code from previous class. Without using threshold values, answer 1 and elaborate on result from 1 to code 2 using energy principles. Please check(if possible on glowscript vpython) if it works. Web VPython 3.2
# CONSTANTS
G =6.7E-11 # N*m^2/kg^2, gravitational constant
RE=6.4E6
mEarth =6.0E24 # kg, mass of the Earth
mcraft =9600 # kg, mass of the Dragon capsule
deltat =60 # s, timestep for iterative calculation
RE =6.4E6 # m, radius of the Earth
# OBJECTS AND INITIAL VALUES
Earth = sphere(pos=vector(0,0,0), radius=6.4E6, color=color.cyan, opacity=0.5) # Make Earth transparent
craft = sphere(pos=vector(-3*Earth.radius, 0,0), radius=1E6, color=color.yellow)
trail = curve(color=color.white) # trail object to show the craft's trajectory
# Initially, the capsule is at rest
vcraft = vector(0,0,0) # m/s, initial velocity (at rest)
pcraft = mcraft * vcraft # Initial momentum
# Arrow representing momentum
#scalefactor = Earth.radius/pcraft.mag# Arbitrary scaling factor for visualization
scalefactor =0.1
momentumarrow = arrow(pos=craft.pos,axis=pcraft,color=color.magenta)
# ITERATIVE CALCULATIONS
t =0 # initial time
tfinal =24*60*60 # simulate for one day (in seconds)
while t tfinal:
rate(100) # animation rate (frames per second)
# Position vector from Earth's center to the capsule
r = craft.pos - Earth.pos
rmag = mag(r) # Magnitude of r (distance from center of the Earth)
rhat = norm(r) # Unit vector in the direction of r
if rmag RE: # When capsule is inside the Earth
# Gravitational force inside the Earth
Fmag = G * mEarth * mcraft * rmag /(Earth.radius**3)
else: # Outside the Earth (not applicable for this problem, but keeping it general)
Fmag = G * mEarth * mcraft /(rmag**2)
FG =-Fmag * rhat # Gravitational force vector (directed towards Earth's center)
# Update momentum and position
pcraft = pcraft + FG * deltat # Update momentum
craft.pos = craft.pos +(pcraft / mcraft)* deltat # Update position
# Update trail and momentum arrow
trail.append(pos=craft.pos) # Add new point to the trail
momentumarrow.axis = pcraft * scalefactor # Update arrow axis to reflect momentum
momentumarrow.pos = craft.pos # Update arrow position to follow the capsule
# Update time
t = t + deltat
# Stop the simulation once it reaches the other side of the Earth (at -RE,0,0)
if rmag =0: # When it reaches the center or passes through
break
This is the code from previous class. Without

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!