Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. Ball Trajectory Game Write a MATLAB program to create a game that prompts user to enter the speed and angle with which a ball
2. Ball Trajectory Game Write a MATLAB program to create a game that prompts user to enter the speed and angle with which a ball is thrown to hit a randomly placed target The height h) and horizontal distance x() traveled by a ball thrown at an angle A and speed v are given by the following equations h() - vrsin A- gr/2 x(t) vt cos A The acceleration due to gravity is g = 9.81 m/sec. The user gets three tries to hit a target with a ball. Your program should solve the following problems: Create a target (a small square) on the ground at a random distance from origin and display this value to the user Prompt the user to enter the value of initial velocity v between 0 and 100 m/ sec and angle A between 0 and 90 degrees. If the user enters a value that lies outside these bounds, prompt the user to re-enter that value. Use the values of v and A to numerically calculate and plot the ball's trajectory (plot h versus x for positive values of h). Use the axis command to restrict the height to positive values. Find the maximum distance xmax traveled by the ball. a. b. c. d. Plot the trajectory for the given values of v and A e. Check whether the ball has landed at a location that is at distance +0.25 m from target. If yes, it is a hit. If the ball hits the target successfully, the program should display "Hit" and exit; otherwise, it should display "Miss" and continue until three tries are up Note: Run the program in the file lab7p to see how your program should work Output Format: Your program must display the location of the target and the trajectory created by the ball when it is thrown each time
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started