CSC 130 programming help

profileIT_homework2
balisticshelp.docx

This file is provided as a help to the physics, and was copied from:

http://physics.tutorvista.com/motion/projectile-motion.html

Projectile Motion Equation

Projectile motion is a two dimensional concept and it follows the two dimensional kinematics. A projectile has both the horizontal and the vertical components of motion. Projectile motion can be stated as the:

y = 1/2 (at2) + v0 t + y0

Where, y = height t = time  a = acceleration of the projectile because of gravity V0 = Initial velocity of the projectile Y0 = Initial height of the projectile

Horizontal Component of the Velocity: Whenever the projectile is thrown or follows the trajectory, the horizontal component of the velocity does not changes and the displacements covered by the horizontal components of the velocity are uniform. In other words, final horizontal velocity component is equal to the initial velocity component.

Now the point here to note is that when the projectile follows the trajectory, gravity force does not affect or does not make any change in the horizontal velocity component of the velocity.

Vertical Component of the Velocity: Vertical component of the velocity does not remain constant during the projectile motion. Gravity force acts on it and changes the vertical component of the velocity of the projectile. The displacements covered by the vertical component of the velocity are not uniform.

For the vertical component of the velocity during the projectile motion, change in both the magnitude and direction takes place. If the projectile is moving in the upward direction, then the vertical component of the velocity is in the upward direction and decrease in its magnitude takes place. 

On the other hand, when the projectile moves in the downward direction, the direction of the vertical components of the velocity is in the downward direction and increase in the magnitude takes place.

Range Equation for Projectile Motion

Equations involving Vertical Motion

Equations involving Horizontal Motion

Explanation of Symbols used

V(iy) = Vi sinθ

V(ix) = Vi cosθ

· Vi = Magnitude of Initial Velocity

· V(iy) = Y component of Initial Velocity

· V(ix) = X component of Initial Velocity

V(fy) = V(iy) + ay t

V(fx) = V(ix)

· Vfy = Y component of Velocity at time 't'

· Vfx = X component of Velocity at time 't' (note that the X component remains constant)

· ay = acceleration in vertical direction, which in the case of projectile motion would be -9.8 m/s2

Yf - Yi = V(iy) t + 1/2 ayt2

Xf - Xi = V(ix) t 

· Yi = Initial Y co-ordinate of Projectile

· Yf = Y co-ordinate of Projectile at time 't'

· Xi = Initial X co-ordinate of Projectile

· Xf = X co-ordinate of Projectile at time 't'

(Vfy)2 = (V(iy))2 + 2ay(Yf- Yi)

Symbols already described above

Yf - Yi = t(V(iy)+V(fy))/2

Symbols already described above

Maximum Projectile Range : Expression Now, let’s look at the expression for projectile range using the above formula, Let the projectile start at (0, Yi) co-ordinates with a speed of Vi = v, and angle θ with the horizontal surface. After some time t, it strikes the ground at a distance of Xf. The value of Xf gives the range of the projectile The figure given below aids the visualization of the motion:

Projectile Range

In this figure, the range of the projectile is given by the formula, d =  Xf  = ((Vcosθ)/g)  (Vsinθ+ √ ((Vsinθ)^2+2gYi)) Using the above equation one can make a graph of `theta` versus `d` for different `theta`, and see where the value of `d` maximizes. This will be the value of maximum projectile range. Moreover, this equation reduces to a very simple form when the projectile starts form ground level, that is when Yi = 0. The equation then becomes:

d =  Xf  = (2V^2cosθsinθ)/g

Which can then be simplified to the following expression:

d =  Xf  = (V^2sin(2θ))/g

Using the above equation we can very easily find the expression for maximum projectile range in this simple situation. We know that the maximum value of sin 2θ is 1. Therefore, the maximum range of the projectile is d =  Xf  =  V^2g Also, the value of 2θ for which sin 2θ = 1 is 90∘. Therefore, the value of θ = 90/2 = 45∘

Now we can look at how to convert an equation into code.

If my equation were:

d =  Xf  = ((Vcosθ)/g)  (Vsinθ+ √ ((Vsinθ)^2+2gYi))

I would define variables for each of the components of the equation.

d would be defined by: double distanceX = 0.0;

V would be defined by: double initialVelocity = 0.0;

θ would be defined by: double shotAngle = 0.0;

g would be defined by: double accelerationY = -9.81; (This is the acceleration of gravity in meters/(second squared))

Yi would be defined by: double distanceY = 0.0;

Now I could write out the equation;

distanceX = ((initialVelocity*Math.cos(shotAngle))/ accelerationY)*( initialVelocity*Math.sin(shotAngle) + Math.sqrt(Math.pow(initialVelocity*Math.sin(shotAngle, 2)) + 2 * accelerationY * distanceY );

But this is a mess. Better would be:

If I also define a few intermediate variables.

double velocityX = 0.0;

double velocityY = 0.0;

double ValueToSquareRoot = 0.0;

and do a little creative combining.

velocityX = initialVelocity * Math.cos(shotAngle);

velocityY = initialVelocity*Math.sin(shotAngle);

ValueToSquareRoot = Math.pow(velocityY, 2)) + 2 * accelerationY * distanceY;

I am able to reduce the clutter, and make my code more readable.

distanceX = (velocityX / accelerationY) * (velocityY + Math.sqrt(ValueToSquareRoot);

Now in order to find the time of flight or total time the projectile to cover the distance I would need the following two equations.

(Vfy)2 = (V(iy))2 + 2ay(Yf- Yi)

V(fy) = V(iy) + ay t

Notice in the first equation that Yf- Yi is the tower height and that it solves the V(fy) component of the second equation. Thus if we combine the equations we would get:

t = (√ ((V(iy))2 + 2ay(Yf- Yi)) - V(iy) )/ ay neatly solving for time.

If you look at the units for the equation:

d =  Xf  = ((Vcosθ)/g)  (Vsinθ+ √ ((Vsinθ)^2+2gYi))

you will see that the units cancel to that of distance.

m = ((m/s)/m/s^2)(m/s + ((m/s)^2 + (m/s^2)m)^1/2)

m = (s)(m/s + ((m^2/s^2) + (m^2/s^2))^1/2

m = s(m/s + (m^2/s^2)^1/2

m = s(m/s + m/s)

m = s(m/s)

m = m

The other equations similarly cancel to appropriate units.