#==================== # Figure 9.11.R. # R script to calculate and graph # projectile motion (such as # throwing a baseball). #==================== #--------------------------------------------------------------- # Input initial velocity, angle, and height, in USA common units. #--------------------------------------------------------------- mph=75 # Initial velocity, miles per hour. angle=45 # Initial angle, degrees. height=5 # Initial height, feet. #--------------------------------------------------------------- # Convert units to meters and seconds. #--------------------------------------------------------------- v0=mph*1609.344/(60*60) # Convert velocity to meters per second. theta=2*pi*angle/360 # Convert angle to radians. y0=height/3.2808399 # Convert height to meters. g=9.80665 # Gravitational acceleration constant. #--------------------------------------------------------------- # Calculate maximum time of flight using quadratic root formula. #--------------------------------------------------------------- a=-g/2 b=v0*sin(theta) c=y0 t.max=(-b-sqrt(b^2-4*a*c))/(2*a) # Max. time of flight. x.max=v0*cos(theta)*t.max # Max. distance #--------------------------------------------------------------- # Plot height at time t vs distance at time t. #--------------------------------------------------------------- t=t.max*(0:50)/50 # Range of t values between 0 and t.max. x=v0*cos(theta)*t y=y0+v0*sin(theta)*t-g*t^2/2 plot(x,y,xlab="distance in meters",ylab="height in meters") # Plot. t.max # Print t.max. x.max # Print x.max