705003 Engineering Computing

Total Page:16

File Type:pdf, Size:1020Kb

705003 Engineering Computing

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 Pseudocode display program title enter height h, speed s, elevation angle a calculate initial values: x0, y0, vx0, vy0, k [initialise xprev and yprev, say xprev = 0 and yprev = h] display table title at each required time t (0, 0.01, ....1.00 seconds) calculate x, y (it will also be useful to calculate vx, vy, v to check the formulas are correct) display t and the calculated numbers if ball is at the net if ball is below net height display "hit the net" else display "over the net" if ball has just hit the ground if ball is too far display "hit too far" else display "good serve" [save x and y for next time (xprev = x and yprev = y)] display end of program Sample Program Input and Output The following shows typical input and output, and demonstrates the required input validation. (User input is shown bold and underlined.) TRAJECTORY Enter height of serve (m): 0 ERROR: Height must be greater than zero. Enter height of serve (m): 2.5 Enter speed of serve (m/sec): 0 ERROR: Speed must be greater than zero. Enter speed of serve (m/sec): 30 Enter elevation angle of serve (degrees): -90.1 ERROR: Angle must be between -90 and +90 degrees. Enter elevation angle of serve (degrees): 90.1 ERROR: Angle must be between -90 and +90 degrees. Enter elevation angle of serve (degrees): 1 INITIAL VALUES x0 = 0.000 y0 = 2.500 s = 30.000 a = 1.000 vx0 = 29.995 vy0 = 0.524 k = 0.03420 CALCULATED TRAJECTORY t x y vx vy v 0.00 0.000 2.500 29.995 0.524 30.000 0.01 0.299 2.505 29.816 0.423 29.819 0.02 0.596 2.508 29.638 0.322 29.639 0.03 0.892 2.511 29.460 0.223 29.461 0.04 1.186 2.513 29.284 0.124 29.284 0.05 1.477 2.514 29.109 0.025 29.109 ... 0.45 11.829 1.798 22.898 -3.465 23.159 0.46 12.058 1.763 22.761 -3.542 23.035 Over the net at height = 1.763 m 0.47 12.284 1.727 22.625 -3.619 22.912 0.48 12.510 1.690 22.489 -3.695 22.791 0.49 12.734 1.653 22.355 -3.770 22.671 0.50 12.957 1.615 22.221 -3.845 22.551 ... 0.80 19.058 0.144 18.561 -5.903 19.477 0.81 19.243 0.084 18.450 -5.965 19.390 0.82 19.427 0.024 18.339 -6.027 19.304 0.83 19.610 -0.036 18.230 -6.089 19.219 Hit too far, distance = 19.610 m 0.84 19.792 -0.098 18.121 -6.150 19.136 0.85 19.972 -0.159 18.012 -6.211 19.053 ... 0.95 21.720 -0.810 16.963 -6.800 18.275 0.96 21.890 -0.878 16.862 -6.857 18.203 0.97 22.058 -0.947 16.761 -6.914 18.131 0.98 22.225 -1.017 16.661 -6.970 18.060 0.99 22.391 -1.087 16.561 -7.026 17.990 1.00 22.556 -1.157 16.462 -7.082 17.921 END OF PROGRAM

Recommended publications