How can I incorporate wind resistance into my projectile motion calculations?

AI Thread Summary
Incorporating wind resistance into projectile motion calculations complicates the equations, as the vertical and horizontal motions become interdependent, requiring the use of coupled differential equations. The wind resistance can be modeled with a force proportional to the square of the velocity, leading to the need for numerical methods like Euler's method for simulation. The key equations involve calculating the forces in both the x and y directions, adjusting velocities based on these forces, and updating positions iteratively. The discussion highlights the importance of correctly implementing these equations in code, particularly in Python, to track the projectile's trajectory over time. Understanding these principles is essential for accurately predicting the projectile's behavior under the influence of wind resistance.
python
Messages
7
Reaction score
0

Homework Statement


I'm currently in computer programming class, and I've finished a project and want to improve on it. We had to figure out how to calculate the gravitational acceleration and time traveled of a projectile to hit a target. I'd like to add horizontal variables in my code, like wind resistance left and right. What would the formula be for something like this? The user inputs the initial velocity and also the launch angle.
v = velocity
r = launch angle in radians
g = gravitational acceleration

Homework Equations


time of travel = 2 * v * sin(r) / 32
distance = velocity * cos(r) * time

The Attempt at a Solution


No attempt, don't know the correct equation.
 
Physics news on Phys.org
Your equations for the version without wind resistance look fine. Apparently you are using U.S. customary units (feet and seconds).

Adding in wind resistance makes the problem vastly more difficult. A key problem is that wind resistance makes it so that the vertical part of the motion and the horizontal part of the motion are no longer independent. Instead they become a pair of "coupled" differential equations. You cannot solve for time of flight based purely on initial vertical velocity. You cannot solve for distance traveled based purely on time of flight and initial horizontal velocity. You have to solve the two equations together.

One way proceed to split the time interval into small pieces and work a simulation forward one tick at a time. Keep track of the projectile's vertical and horizontal position and its vertical and horizontal velocity. Run the simulation in a loop until the vertical position becomes negative.

Suppose that the wind resistance formula take the form: f = -kv^2 for some constant k and that you have the current position and velocity stored in variables x_cur, y_cur, vx_cur and vy_cur. Can you write code to compute a reasonable approximation for x_next, y_next, vx_next and vy_next?
 
jbriggs444 said:
Your equations for the version without wind resistance look fine. Apparently you are using U.S. customary units (feet and seconds).

Adding in wind resistance makes the problem vastly more difficult. A key problem is that wind resistance makes it so that the vertical part of the motion and the horizontal part of the motion are no longer independent. Instead they become a pair of "coupled" differential equations. You cannot solve for time of flight based purely on initial vertical velocity. You cannot solve for distance traveled based purely on time of flight and initial horizontal velocity. You have to solve the two equations together.

One way proceed to split the time interval into small pieces and work a simulation forward one tick at a time. Keep track of the projectile's vertical and horizontal position and its vertical and horizontal velocity. Run the simulation in a loop until the vertical position becomes negative.

Suppose that the wind resistance formula take the form: f = -kv^2 for some constant k and that you have the current position and velocity stored in variables x_cur, y_cur, vx_cur and vy_cur. Can you write code to compute a reasonable approximation for x_next, y_next, vx_next and vy_next?
Yes, I could make the variable count upwards or downwards. Would it be a constant curve?
 
I'm not sure that we are understanding one another. Can you show what you had in mind?
 
jbriggs444 said:
I'm not sure that we are understanding one another. Can you show what you had in mind?
This is what my code prints out for the user.

Attempt 1
-----------
The target is 2914 feet away.
Input the velocity.400
Input the launch angle15
Too short.
You were 414.00 feet away!
Distance traveled was 2500.00 feet
It took you 6 seconds travel time.

I want to add code to calculate how far left or right the projectile will go when I add wind to it.
 
What would code look like to compute where the projectile would be one tenth of a second after launch?
What would code look like to compute what velocity the projectile would have one tenth of a second after launch?
 
jbriggs444 said:
What would code look like to compute where the projectile would be one tenth of a second after launch?
What would code look like to compute what velocity the projectile would have one tenth of a second after launch?
I could use my original variable, time, to find one tenth of a second, the line would look like this.
variable is time
time - time + .1 = new variable
That would be easy to find, however, I don't know how to calculate the decline of velocity. I'm not currently a physics student, I'm taking that next year.
 
python said:
I could use my original variable, time, to find one tenth of a second, the line would look like this.
variable is time
time - time + .1 = new variable
Help me out here. What programming language do you use where the result of an assignment statement is on the right? And why would one write "time - time + 0.1" when one could simplify and write "0.1" instead?
 
jbriggs444 said:
Help me out here. What programming language do you use where the result of an assignment statement is on the right? And why would one write "time - time + 0.1" when one could simplify and write "0.1" instead?
Sorry, I didn't know if you knew code.
I'm using python for this project.
The code would look something like:
newvar = .1
And as long as I have the equation, I can figure out the code for it. I just need the formula really, and maybe an explanation for it.
 
  • #10
The differential equations of motion for wind resistance that scales as the square of velocity would be:

##f_x = -kv^2\frac{v_x}{|v|}##
##\frac{dv_x}{dt} = \frac{f_x}{m}##

##f_y = -mg -kv^2\frac{v_y}{|v|}##
##\frac{dv_y}{dt} = \frac{f_y}{m}##

Setting newvar to 0.1 is only a small part of the job. What I am proposing is Euler's method to solve this differential equation numerically.
 
  • #11
jbriggs444 said:
The differential equations of motion for wind resistance that scales as the square of velocity would be:

##f_x = -kv^2\frac{v_x}{|v|}##
##\frac{dv_x}{dt} = \frac{f_x}{m}##

##f_y = -mg -kv^2\frac{v_y}{|v|}##
##\frac{dv_y}{dt} = \frac{f_y}{m}##

Setting newvar to 0.1 is only a small part of the job. What I am proposing is Euler's method to solve this differential equation numerically.
Could you explain the equation to me? Also, I could just calculate the resistance for one tenth of a second, and then multiply by the variable time to get the total distance traveled left or right?
 
  • #12
python said:
Could you explain the equation to me? Also, I could just calculate the resistance for one tenth of a second, and then multiply by the variable time to get the total distance traveled left or right?
No. Multiplying a constant velocity by time gets you distance travelled. Multiplying a variable velocity by time gets you garbage.

The first equation expresses the x component of force in terms of a constant k and the current velocity of the projectile. The constant represents a combination of how viscous the atmosphere and how large the cross-section of the projectile is. The total wind resistance scales with the square of the current velocity. That explains the v2 term. The vx/v term is there to express the fact that we are interested in only the x component of that force.

The second equation expresses how the rate of change of the x component of velocity with respect to time (dvx/dt) is equal to the x component of force divided by the mass of the projectile. This is Newton's second law, f=ma, rearranged by dividing through by m and expressing a as dv/dt.

The third equation expresses the y component of force. Again, there is the wind resistance component which is entirely analogous to the x component. In addition, there is the downward force of gravity.

The fourth equation is entirely analogous to the second.

You would use these equations by first computing fx based on the starting velocity using equation 1.
You would then compute the rate of change of vx based on fx using equation 2.
You would update the x position by adding the current velocity time the length of your selected time increment.
You would then update the x velocity by multiplying the dvx/dt by your selected time increment.

You would then use the entirely analogous process for the y component.

After performing these manipulations you should have a new x velocity, a new y velocity, a new x position, a new y position and a new time.

Your first task is to come up with a set of variable names to represent these quantities. Your second task is to write the code to perform one step of the computation. Can you do that and show us what you come up with?
 
  • #13
vSquared = v ** 2
force = -14.7 * vSquared
change =
yForce =
yChange =
This is what I got, but when I print it off to the console, it gives me a number in the millions. Am I doing something wrong?
 
Back
Top