Programming a Projectile Motion Question

AI Thread Summary
The discussion revolves around programming a projectile motion question, focusing on the calculations for time to a wall and height at impact. The user encounters confusion when the calculated height is negative, indicating the projectile hits the ground before reaching the wall, which is a valid outcome given the low initial velocity. Clarifications suggest that the negative height should not be converted to an absolute value, as it accurately reflects the projectile's trajectory. The conversation emphasizes the importance of adjusting initial velocity and understanding the physics behind projectile motion to ensure accurate results. Ultimately, the user gains a better grasp of how to handle inputs and outputs in their programming project.
defiledx
Messages
6
Reaction score
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
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.
 
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?
 
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?
 
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:
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
 
... 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?
 
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.
 
Hmm accidentally quoted myself and can't delete it...
 
Back
Top