In: Computer Science
Write a function that plots the following trajectory equations using python turtle graphics.
x = v*sin(A)*t
y = v*cos(A)*t -.5*(9.8)*t**2
Loop through t starting at 0 and increment by .1 until y<=0. (hint, while loop) Experiment with values of velocity V (1 to 20) and angle A (0 to 90) that gives you a good plot that does not go off the screen. Position the start of the plot at the left bottom of the screen
import math
import turtle
#declare v,A as a global value
v = 20
A = math.radians(45) #Convert the angle to radians
#define x and y as functions
def x_val(t):
return v*math.sin(A)*t
def y_val(t):
return v*math.cos(A)*t - 0.5*9.8*(t**2)
#driver code for printing
tS = turtle.Screen() # open the turtle screen
tT = turtle.Turtle() # initiate the turtle
t = 0
x_prev = 0 # prev value of x
x_curr = 0 # curr value of x
y_prev = 0 # prev value of y
y_curr = 0 # curr value of y
while y_curr >= 0.0: # Untill y is not negative loop
# turtle by default is facing right
tT.forward(x_curr - x_prev) # use forword to displace by difference in positions
tT.left(90) # turn turtle upward
tT.forward(y_curr-y_prev) # update y direction
tT.right(90) # turn the turtle to face right for next update
t += 0.1 # update the time
x_prev = x_curr
y_prev = y_curr
x_curr = x_val(t)
y_curr = y_val(t) # update the x,y coordinates
turtle.done()