Question

In: Computer Science

Write a function that plots the following trajectory equations using python turtle graphics. x = v*sin(A)*t...

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

Solutions

Expert Solution

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()


Related Solutions

Write a function that draw your initials. (Using python 3 turtle) (T, S)
Write a function that draw your initials. (Using python 3 turtle) (T, S)
with python, create a fake logo for a company using turtle graphics
with python, create a fake logo for a company using turtle graphics
I need to write these three functions in Python using turtle module. def line(t, coord1, coord2)...
I need to write these three functions in Python using turtle module. def line(t, coord1, coord2) t is a turtle object passed in coord1 and coord2 are 2-element lists that represent x, y coordinates draws a line from coord1 to cord2 def poly(t, *coords) t is a turtle object passed in *coords is any number of x, y coordinates each as a 2-element list draws a polygon based on coords (will close off polygon by drawing a line from last...
The cycloid has parametric equations x = a(t + sin t), y = a(1 - cos...
The cycloid has parametric equations x = a(t + sin t), y = a(1 - cos t). Find the length of the arc from t = 0 to t = pi. [ Hint: 1 + cosA = 2 cos2 A/2 ]. and the arc length of a parametric
Using Python write a function that implements the following two-dimensional objective function: F (x, y) =...
Using Python write a function that implements the following two-dimensional objective function: F (x, y) = (x^2 + y − 11)^2 + (x + y^2 − 7 )^22 . Determine how many local minimums and maximums and their location for this objective function.
Write a Python graphics program that draws the following shapes: • window size: 250 x 250...
Write a Python graphics program that draws the following shapes: • window size: 250 x 250 pixels with window title with your name • big circle, 50 pixels radius with center at (125, 125) • two green circles, 10 pixels radius; first one centered at (113, 113) and second centered at (137, 113) • one red line, from (100, 150) to (150, 150) Then answer this, what do you see? (make this a comment in your code)
Assignment Write a program using turtle graphics which writes your initials, or any other three unique...
Assignment Write a program using turtle graphics which writes your initials, or any other three unique letters, to the display. Look to your program for lab 1 for reminders of how to use turtle graphics. Functions that must be written: def drawLetter (x, y, letterColor): Write three functions, one for three unique letters. Personally, I would write drawA, drawR, and drawS. Each function must draw that letter to the screen. The x and y values determine the upper left-hand location...
Write a python program to calculate the value of sin(?) using its Taylor series expansion: sin(?)...
Write a python program to calculate the value of sin(?) using its Taylor series expansion: sin(?) = ? − ? 3 3! + ? 5 5! − ? 7 7! + ? 9 9! … The program should consist of the following functions: a) Develop and test a calcSin() function that receives as an argument, of type float, the value of the variable and returns the result as a float also. Include 20 terms maximum from the series, or until...
Write a function named cup that uses a turtle parameter t to draw a cup consisting...
Write a function named cup that uses a turtle parameter t to draw a cup consisting of three sides of a square. Your function should not change the position or orientation of t before drawing the first side of the cup. The turtle t that is passed to cup may initially be either up or down and may be at any location on the screen and in any orientation. After drawing a side, the turtle t should turn left. When...
I'm stuck on this python exercise using plots Consider the hyperbolic paraboloid function: z=x^2−y^2 Create several...
I'm stuck on this python exercise using plots Consider the hyperbolic paraboloid function: z=x^2−y^2 Create several plots of the hyperbolic paraboloid function. Use true aspect ratio and label all axes. Any help would be appreciated!Matlab can be used as long as the code can be used in Python as well
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT