705003 Engineering Computing
Total Page:16
File Type:pdf, Size:1020Kb
705003 Engineering Computing 2012 Assignment 1 Tennis Ball Trajectory
Assignment Value 10% of total mark for this paper. Date and Time Due 8am Monday 20 August 2012. Requirements Design and implement a C++ program for the following specification. Submitting Your Assignment You must upload a copy of your C++ program source code (.cpp) file to Turnitin by 8am on Monday 20 August 2012. The file needs to be renamed as a text (.txt) file before it is submitted. To make a submission to Turnitin: Log in to AUTonline and go to the page for this paper. Click on the "Assessment" button. Follow the Turnitin link "View/Complete" for "Assignment 1". Your marked assignments will be returned in the lab classes. To ensure you receive your marked assignment, your file name must start with your lab stream number (50 to 55) followed by an underscore and your 7 digit student id number. For example: 50_0123456filename.cpp The lab stream numbers are: 52 = Monday, 53 = Tuesday 8-10am, 54 = Tuesday 2-4pm, 51 = Wednesday, 50 = Thursday, 55 = Friday. Use the lab stream number you actually attend, if it is different from the stream you have been allocated. Assessment The assessment of your program will be based mainly on (but may not be limited to) the following aspects: Source code is correctly and adequately documented (commented and well laid out, with appropriate variable names). Source code compiles and links ("builds") without (significant) warnings. Executable code runs correctly (for test input supplied by the assignment marker, similar to the sample input/output in this specification). Program Specification Inputs Write a program to calculate the trajectory (flight path) of a tennis ball when it is served, and display whether it goes over the net successfully and hits the ground in the "service box" on the other side of the net. (Reference: http://en.wikipedia.org/wiki/Tennis). When the program is run, the user will enter: h = height of the ball when it is hit s = speed of the ball just after it is hit a = elevation angle of the ball trajectory just after it is hit Mathematical Theory Reference: http://en.wikipedia.org/wiki/Trajectory_of_a_projectile We will assume that the ball's trajectory (after it is hit) is affected by the forces of gravity (mg) and air resistance (kv), where v is the ball speed. In fact air resistance is proportional to v2 but there is no mathematical solution for this more realistic situation, so we will use kv. We will assume the ball then follows a trajectory according to the following equations:
x is the horizontal distance travelled and y is the height above the ground. It may be helpful to use the formulas for ball speed, to help check the program results are correct:
When k = 0 (ignoring air resistance) these equations reduce to the standard projectile equations:
The constants in the formulas are: m = 57 gm = 0.057 kg (mass of a tennis ball) g = 9.8 m/sec2 k = 0.00114s N.sec/m (where s is the initial ball speed when it is hit) k is assumed to be constant during the ball flight. This will over estimate the effect of air resistance, so the actual ball speed during flight will be greater than the calculated ball speed. The initial values are calculated from the user input: x0 = 0 y0 = h v0 = s vx0 = s.cos(a) vy0 = s.sin(a) Initial Values Initial Height Good tennis players hit the ball at a height about 1.5 times the player's actual height. Initial Ball Speed The fastest recorded serves in recent times are: 70 m/sec (252 km/hour) by Ivo Karlovic (Croatia) in 2011 and 56 m/sec (200 km/hour) by Venus Williams (USA) in 1998. "Big Bill" Tilder is reputed to have hit a serve at 73 m/sec (260 km/hour) in 1931, but this is in doubt now. Initial Elevation Angle To get a good serve, the elevation angle may need to be negative. This means the server is hitting the ball slightly downwards. The greater the height of the serve and the faster the serve, the more likely the serve angle will be downwards (negative) to get a good serve. Characteristics of a Good Serve Assume the ball is served straight down the tennis court. Then: the distance to the net is 11.887 m (39 feet), take the net height as 1.000 m (actually 0.914 to 1.067 m, 3.0 to 3.5 feet), the distance to the far side of the service box is 18.288 m (60 feet). To get over the net, the ball must have a height y of at least 1.000 m, after it has travelled a horizontal distance x of 11.887 m. To land inside the service box, the ball must get over the net AND have a height y less than or equal to zero before is has travelled a total horizontal distance x of 18.288 m from where it was served. Program Logic and Other Calculations Calculate the ball position for values of time from zero to one second (inclusive) in steps of 0.01 seconds. After each calculation: if the ball is at the net (previous distance < distance to net and current distance ≥ distance to net), display whether the ball hit the net or went over the net. if the ball has hit the ground (previous height > zero and current height ≤ zero), display whether or not the ball hit the ground inside the service box. To check if the ball has just reached the net, your program needs to have the previous x value as well as the current x value, so at the end of each calculation save x to another variable, such as xprev. xprev needs to be initialised before starting the calculations so it will always have a sensible value. A reasonable starting value is 0. If the ball hits the net, return 1 to stop the program. To check if the ball has just hit the ground, your program needs to have the previous y value as well as the current y value, so at the end of each calculation save y to another variable, such as yprev. yprev needs to be initialised before starting the calculations so it will always have a sensible value. A reasonable starting value is h. Remember the trig functions need angles in radians, so the angle entered in degrees needs to be converted to radians. Use the value of is named M_PI in the cmath header file. To use this, you need to define _USE_MATH_DEFINES before including cmath, as follows: #define _USE_MATH_DEFINES #include