COE 312 Project 2, Fall 2012

Lebanese American University · Data Structures · 6 pages · Dr. Wissam Fawaz

All COE 312 files
COE 312 Project 2, Fall 2012, page 1

Stuck on a question? A tutor can walk you through it.

COE 312 Project 2, Fall 2012, page 2 COE 312 Project 2, Fall 2012, page 3 COE 312 Project 2, Fall 2012, page 4 COE 312 Project 2, Fall 2012, page 5 COE 312 Project 2, Fall 2012, page 6

More COE 312 files

Show the text of this project
COE 312 Data Structures Fall 2012 W. FAWAZ Projects II Project II (Due date: Thursday December 20, 2012) I. Objective In this project, you will be creating a projectile motion simulator. In particular, your job is to develop a user interface that would allow the end user to launch an “angry bird” through mouse click events. So, the main actor in your simulator will be an “angry bird” character from the famous “Angry Birds” game. If you are not familiar with the said game, note that it is a game where the player uses his finger to launch birds attempting to destroy structures and enemy pigs. Given that your implementation will be targeting personal computers rather than mobile phones, your end user is required to use his mouse to interact with the angry bird. While the premise of the project is very appealing, simulating the motion of an “angry bird” projectile is somewhat a challenging task. Now, if you are a little worried about having to deal with heavy physics and mathematics, don’t worry! You do not need to go very deep into it, and the formulas you shall use are really quite simple. II. Problem: Frictionless Projectile motion The trajectory followed by the angry bird will depend on both the angle θ relative to the horizon as well as on the initial velocity V0 as shown in Figure 1. Let us denote by T the total hang time, which is the amount of time the projectile remains in the air. The projectile hits the ground at a horizontal distance x=R away from the launching point. L E B A N E S E A M E R I C A N U N I V E R S I T Y Electrical and Computer Engineering Dept Figure 1. Trajectory of projectile A program that simulates the motion of a projectile has to go through the following steps: 1. Determine the values of θ and V0 2. Setup the “equations of motion” that govern the evolution of the position of the projectile 3. Compute the “hang time” T, the range R, and the height H from the equations of motion 4. Vary the position of the projectile as a function of time based on the equations of motion The above-presented steps are discussed in great details in what follows. III. Determining the values of θ and V0 To make the “angry bird” object move from its initial position, the end user is expected to apply some force to that object. The way the “angry bird” is pushed is as follows. The user will have to click the left mouse button over the “angry bird” object and then drag the mouse while the mouse button is held down. When the button is released, the “angry bird” object is launched. It is clear that the process of giving a push to the object will result in the creation of two points that we denote by P1 and P2 respectively. As a matter of fact, when the mouse is first pressed over the “angry bird”, the coordinates of P1 are set. After the mouse is dragged and released the coordinates of the second point P2 are set. Figure 2. Components of V0 projected onto the x and y axes It is important to note that the angle between the line connecting P1 to P2 and the horizontal axis represents the θ angle that we referred to earlier. Furthermore, it is worthwhile noting that the speed with which the mouse was dragged dictates the value of the initial velocity V0. In other words, one can determine the value of V0 by computing the value of the speed at which the mouse was dragged. This can be easily achieved by dividing the distance between P1 and P2 by the amount of time it took the mouse pointer to move from P1 to P2. Use Google to find out how the distance between two points in a two-dimensional plane can be calculated. As for the amount of time to go from P1 to P2, you can derive it by relying on the “currentTimeMillis()” static method of the Java class called “System”. Having determined the values of θ and V0, you are now ready to proceed to the second phase of this project, in which you will simulate the projectile motion of the launched “angry bird”. The details pertaining to the formulas that govern the motion of a projectile are explained next. IV. Setting up the equations of motion In the context of a frictionless projectile motion scenario such as the one we are considering in this project, the projectile will only be affected by the force of gravity. This is especially true since the friction due to air is ignored. The force of gravity causes the projectile to fall towards the center of the earth with a constant acceleration g=9.8m/s2. The resulting solutions to the equations of motions are: Here V0x and V0y are the horizontal and vertical components of the initial velocity. And, as we can see from Figure 2, they are given as: The instantaneous horizontal component of the velocity vx(t) remains constant throughout the motion. The instantaneous vertical component of the velocity vy(t) however increases linearly because the acceleration is constant. As such, at any time t, the instantaneous components of the velocity can expressed as follows: The equations of motion characterizing x and y (kindly refer to Eq. (1)) can be used to establish a relationship between x and y and thus to show that the trajectory followed by the projectile is a parabola. Consider Eq. (1). By eliminating t from both of the motion equations given in Eq. (1), we will obtain: As you may have noticed, this is the equation of a parabola, and so the path is parabolic. V. Computing the values of T, R, and H We determine the hang time “T” by observing that at the time of launching t = 0, and landing t = T, the projectile has a height y = 0. If we set y = 0 in Eq. (1), we obtain an equation for the time at which the height is zero: Once we get T, we can find the range R as the horizontal distance x(T): The projectile reaches its maximum height H at the midpoint of the trajectory at time t = T/2 => VI. Simulating the motion of the projectile At this point, you are armed with all the necessary information that is needed to simulate the motion of the projectile properly. More specifically, the parabolic trajectory followed by the angry bird should comply with Eq. (2). In addition, the hang time “T”, the range “R”, and the peak of the object’s motion H should be controlled by Eqs. (3 – 5). Whew! There is a lot more going on than what meets the eye when one plays the angry bird game!  What to turn in? This project is due at the beginning of class on the due date. You have to turn in the following material in both hard and soft copies. Criteria Percentage HTML Documentation of your code. In addition, provide explanations and illustrations in one or two pages along with a short write-up of questions and/or problems that you encountered while doing this assignment. 3 pts (15%) Source code that contains an appropriate amount of comments. Well- organized and correct code receives 16 pts, messy yet working code receives 8 pts, code with bugs receives 2 pts, and incomplete code receives 1 pt. 16 pts (80 %) Execution output such as a snapshot of the contents of standard output. A correct output receives 3 pts, the one with minor errors receives 2 pts, and an incomplete output receives 1 pt. 1 pts (5%) Total 20pts (100%) Good Luck!