Programming a Projectile Motion Question

In summary, the projectile will hit the ground before it hits the wall if the initial velocity is less than or equal to 1m/s and the launch angle is 45 degrees.
  • #1
defiledx
6
0
Warning! All queries in the Homework section must use the Posting Template provided when a new thread is started.
Hello all! I'm trying to program a projectile motion question and I'm having some trouble with the physics that's involved.

The program allows you to input the starting height, initial velocity, launch angle and the distance to a wall (also a window on the wall, but that isn't important for this).

Now the problem states to calculate the time to the wall by t_w = d/cos(theta)*U

That's perfectly reasonable given you can input all the information.

Now it says to use that time to calculate the height at which it hits the wall.

h_w = -0.5*g*t_w^2 + U*sin(theta)*t_w + starting height

If I sub 1m starting height and 1m/s initial velocity, 45 degrees for launch angle and the time to the window (which was approx 1.4s).

The height is approx -7m and we of course take the absolute value for distance.

This is the confusing part...

It now says to calculate the final distance traveled, the height and the total time of flight.

The problem states to use a quadratic formula as h = 0, when it hits the ground.

Using 1m/s, and Sin(45), my quadratic form for time gives 0.5s for final time.

For total distance. d = Ucos(theta)*t it gives me approx 0.3m.

For height it works out to be 0, so this seems to be ok.

But HANG ON, now I have 2 different times and 2 different distances.

The other set of equations says it only travels for 0.5s and stops at 0.3m. I don't understand this... Because the problem suggests that during the motion it goes through the window.

Should I be adding the time to the wall to my final flight time?

Or should I include the input distance to d = Ucos(theta)*t somehow in the final calculation?

I'm really confused.

Hope you can help!

Thanks
 
Physics news on Phys.org
  • #2
The height is approx -7m and we of course take the absolute value for distance.
... I think this is the mistake. A negative number here means that the projectile hits the ground before it hits the wall. There is no reason to take the absolute value unless you happen to know you made a bad substitution.

Put another way - if the ground were not there, then the y=0 line is just a line in space ... the projectile hits the wall 7m below where the ground would be. That makes sense because 1m/s is pretty slow.
 
  • #3
Simon Bridge said:
... I think this is the mistake. A negative number here means that the projectile hits the ground before it hits the wall. There is no reason to take the absolute value unless you happen to know you made a bad substitution.

Put another way - if the ground were not there, then the y=0 line is just a line in space ... the projectile hits the wall 7m below where the ground would be. That makes sense because 1m/s is pretty slow.

So you're saying I shouldn't use 1m/s as initial velocity? And that the -7m was correct to be negative?

Then what does the time mean from: t_w = d/cos(theta)*U ?

Is it wrong to sub in 1m for d, and 1 for U? That means it's an incorrect time?

What test values should I be subbing in?
 
  • #4
defiledx said:
So you're saying I shouldn't use 1m/s as initial velocity? And that the -7m was correct to be negative?

Then what does the time mean from: t_w = d/cos(theta)*U ?

Is it wrong to sub in 1m for d, and 1 for U? That means it's an incorrect time?

What test values should I be subbing in?
So for my program if the value spits out a negative height, I should prompt the user to enter a higher initial velocity?
 
  • #5
So you're saying I shouldn't use 1m/s as initial velocity? And that the -7m was correct to be negative?
I am saying that the negative number was correct - that is where the projectile would hit the wall if nothing else got in the way.
Consider the extreme cases - if the initial velocity were u=0m/s, OR the angle were 90deg ... what's going to happen?

Then what does the time mean from: t_w = d/cos(theta)*U ?
That is the time it would take the projectile to reach the wall if nothing gets in the way.

Is it wrong to sub in 1m for d, and 1 for U?
Well, the projectile with that launch speed and angle and position will hit the ground 60cm from the launch point... i.e. before it hits the wall.
You realize that it is possible for a projectile to fall short right?

What test values should I be subbing in?
Well you could have just put d=0.5m ... then it would hit the wall.
u=2m/s would do it too. You should get used to the equations so yu can answer questions like "what initial velocity do I need to just hit the wall?" etc.

For a projectile starting at position ##(x_0,y_0)##, it's ##(x,y)## position after time ##t## is given by:
##x(t)=x_0 + ut\cos\theta\\
y(t)=y_0 + ut\sin\theta -\frac{1}{2}gt^2##

So for my program if the value spits out a negative height, I should prompt the user to enter a higher initial velocity?
... if the object was to hit the wall above the ground, then I'd say you should get the program to calculate the horizontal distance x traveled, and tell the user "your projectile hit the ground d-x meters from the target" and ask for new inputs. User then explores the way all the inputs affect the range. If the number is positive, you can output "your projectile hit the target at height y meters".

If the wall was h high, and y>h, then you can say the projectile flew over the wall.
If you have to hit a window... you get the idea?
 
Last edited:
  • #6
Thank you so much, you put it all in perspective. I kept thinking something was wrong with how I coded the program...

Yes, I understand now. I kept thinking for some reason that the projectile should have hit the wall no matter what. I was going in circles a lot... maybe I should have posted my question here sooner.

Thanks for giving me a better understanding.

Really appreciate the help :D
 
  • #7
... BTW: to test your program, see how it responds to extreme situations: i.e. what if u=0 or the angle is 90deg? What if the angle is bigger than 90deg? What if u<0? What if u=
300,000,000m/s or more?

How could the user mess up the program - say by using a regexp as an input?
Imagine the user is deliberately and maliciously trying to make the program fail.
Can you come up with fun and imaginative ways your program could respond?
 
  • #8
Simon Bridge said:
... BTW: to test your program, see how it responds to extreme situations: i.e. what if u=0 or the angle is 90deg? What if the angle is bigger than 90deg? What if u<0? What if u=
300,000,000m/s or more?

How could the user mess up the program - say by using a regexp as an input?
Imagine the user is deliberately and maliciously trying to make the program fail.
Can you come up with fun and imaginative ways your program could respond?

I could program something like

If "velocity input' > 3X10^8 Then

MsgBox("Faster than speed of light, huh?")

End if

I'm just learning how to code in this course and it involves some physics. It was fun doing this problem and wrapping my head around all the concepts.

The question I was working on limited the angle to 90 deg, but I could also use the same thing. I'm not great at coding yet, but it's sure a hell of a lot of fun.

I could also do the same if initial velocity is 0 and prompt the user that they didn't enter an initial velocity.
 
  • #9
Hmm accidentally quoted myself and can't delete it...
 

What is projectile motion?

Projectile motion is the motion of an object through the air with only the force of gravity acting on it. It follows a curved path called a parabola.

What is the equation for projectile motion?

The equation for projectile motion is y = y0 + v0y * t - 1/2 * g * t^2, where y is the vertical position, y0 is the initial vertical position, v0y is the initial vertical velocity, t is time, and g is the acceleration due to gravity.

How do you program projectile motion?

To program projectile motion, you need to first define the initial position and velocity of the object. Then, use a loop to calculate the new position of the object at each time step using the equation for projectile motion. You can also use built-in functions or libraries for more advanced coding languages.

What factors affect the trajectory of a projectile?

The factors that affect the trajectory of a projectile include the initial velocity, angle of launch, air resistance, and gravitational force. The mass and shape of the object can also affect its trajectory.

What is the difference between horizontal and vertical motion in projectile motion?

Horizontal motion in projectile motion is constant and unaffected by gravity, while vertical motion is affected by the acceleration due to gravity. This results in a curved path for the object rather than a straight line.

Similar threads

  • Introductory Physics Homework Help
Replies
4
Views
1K
  • Introductory Physics Homework Help
Replies
11
Views
669
  • Introductory Physics Homework Help
Replies
15
Views
20K
Replies
3
Views
3K
  • Introductory Physics Homework Help
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
7
Views
2K
  • Introductory Physics Homework Help
2
Replies
53
Views
3K
  • Introductory Physics Homework Help
Replies
25
Views
2K
  • Introductory Physics Homework Help
Replies
3
Views
2K
  • Introductory Physics Homework Help
Replies
3
Views
1K
Back
Top