Angle required to hit coordinates including air resistance

In summary: So you end up having to do some kind of numerical search anyway. Easiest to just search with the actual simulation, particularly using the zero-drag approximation and/or a lookup of common values as initial guesses.
  • #1
TheShermanTanker
13
4
Hi, I know I've asked this before but I didn't manage to solve the problem before. To give context I'm trying to find the angle to hit a target with given coordinates from my current location in a particular game. (I'm modding the game) I can do it with zero problems when not including air resistance, but the frustrating as hell thing is that solutions with air resistance are rare to come by online. It turns out the most promising solution I came across recently by desmos required the target be the same height at you (Ie both you and target have to be at the same y coordinate. Y is the up and down coordinate in this particular game's physics engine btw), and if you are above the target or below it wouldn't work. Would be great if i could get some help here :)

If it helps, here's how the physics engine models the projectiles:
Gravity: 20m/s2 (Easily solved)
Air resistance: Take the x, y, and z velocities of the projectile and multiply it by 99% 20 times every second. Ie:
Following code is run 20 times every second:
proj.motX = proj.motX * 0.99;
proj.motY = proj.motY * 0.99;
proj.motZ = proj.motZ * 0.99;

The physics engine fortunately does not calculate the surface area, mass or kinematic viscosity of air, phew XD
 
Physics news on Phys.org
  • #2
Does the gravitational acceleration happen first? That is, is the update cycle for the z velocity (calling acceleration due to gravity ##g## and your game time tick ##\delta t##) ##v\rightarrow v-g\delta t\rightarrow 0.99(v-g\delta t)## or is it ##v\rightarrow 0.99v\rightarrow 0.99v-g\delta t##?
 
  • #3
Ibix said:
Does the gravitational acceleration happen first? That is, is the update cycle for the z velocity (calling acceleration due to gravity ##g## and your game time tick ##\delta t##) ##v\rightarrow v-g\delta t\rightarrow 0.99(v-g\delta t)## or is it ##v\rightarrow 0.99v\rightarrow 0.99v-g\delta t##?
Java:
//The block below is called 20 times a second

//This can be ignored
this.locX += this.motX;
this.locY += this.motY;
this.locZ += this.motZ;

float f4 = 0.99F; //Drag

f1 = 0.05F; //Gravity. Since this is called 20 times a second, 0.05 works out to 20m/s2

//Applying drag
this.motX *= (double) f4;
this.motY *= (double) f4;
this.motZ *= (double) f4;

this.motY -= (double) f1; //Applying gravity

//This isn't important given the context, can ignore
this.setPosition(this.locX, this.locY, this.locZ);
 
  • #4
TheShermanTanker said:
If it helps, here's how the physics engine models the projectiles:
Run that simulation for different angles until you find one that is close enough. A binary search should converge quickly, Newton's method even faster. Use the angle without air resistance as the intial point, or precompute a look-up-table of good initial points for combinations of distance and elevation with air resistance.
 
Last edited:
  • #5
A.T.'s method is best - note that you can combine your x and z targets into a "range", so it's a 2d problem.

You can approximate this with a differential equation and solve it to get a closed-form expression for the ##y(t)## and ##r(t)##, where ##r^2(t)=x^2(t)+z^2(t)##. But they both look like ##A+Bt+Ce^{\alpha t}## and you can't eliminate ##t##, ##x##, or ##r## between them. So you end up having to do some kind of numerical search anyway. Easiest to just search with the actual simulation, particularly using the zero-drag approximation and/or a lookup of common values as initial guesses.
 
  • #6
If you are just making a game, then you only need to make it look valid to a casual observer. It doesn't have to be correct. Does your simulation look invalid?
 
  • #7
FactChecker said:
If you are just making a game, then you only need to make it look valid to a casual observer. It doesn't have to be correct. Does your simulation look invalid?
Oh hi, I'm modding an existing game unfortunately, if i was making my own game i would just disable air resistance for special projectiles like these out of laziness XD
 
  • #8
A.T. said:
Run that simulation for different angles until you find one that is close enough. A binary search should converge quickly, Newton's method even faster. Use the angle without air resistance as the initial point, or precompute a look-up-table of good initial points for combinations of distance and elevation with air resistance.
What i understand from this is use v^2 +- sqrt(etc etc) to calculate the angle without air resistance first, then create an imaginary (so called) projectile and simulate it's flight path, collect the data of the simulation and perform corrections to the angle until it's close enough, did i get that right? (Hope i did :P)
 
  • #9
Ibix said:
You can approximate this with a differential equation and solve it to get a closed-form expression for the y(t)y(t)y(t) and r(t)r(t)r(t), where r2(t)=x2(t)+z2(t)r2(t)=x2(t)+z2(t)r^2(t)=x^2(t)+z^2(t). But they both look like A+Bt+CeαtA+Bt+CeαtA+Bt+Ce^{\alpha t} and you can't eliminate ttt, xxx, or rrr between them. So you end up having to do some kind of numerical search anyway. Easiest to just search with the actual simulation, particularly using the zero-drag approximation and/or a lookup of common values as initial guesses.
Could you explain what you mean by this?
Ibix said:
the y(t)y(t)y(t) and r(t)r(t)r(t), where r2(t)=x2(t)+z2(t)r2(t)=x2(t)+z2(t)r^2(t)=x^2(t)+z^2(t). But they both look like A+Bt+CeαtA+Bt+CeαtA+Bt+Ce^{\alpha t} and you can't eliminate ttt, xxx, or rrr between them.
(My background wasn't in physics, i apologise for being dumb)
Ibix said:
So you end up having to do some kind of numerical search anyway. Easiest to just search with the actual simulation, particularly using the zero-drag approximation and/or a lookup of common values as initial guesses.
This is just a guess here, but if i get you correctly what you mean by numerical search/actual simulation would be to get the angle from the equation that excludes air resistance first, fire the projectile at that angle and subject it to air resistance and gravity (Hidden from the player of course), collect data from the flight path, and use the data to perform corrections to the launch angle and repeat this over and over until the angle is correct? (If i vaguely recall someone has told me once that air resistance cannot be discovered from just an equation) Thanks so much for the help btw :)
 
  • #10
TheShermanTanker said:
I'm modding an existing game unfortunately,
This is the worst case. You are not free to make your own simplified model and they might not have valid physics in theirs. So you have to guess what they did. If you want it to be a very close match to their answers, it might be hard.
 
  • #11
TheShermanTanker said:
What i understand from this is use v^2 +- sqrt(etc etc) to calculate the angle without air resistance first, then create an imaginary (so called) projectile and simulate it's flight path, collect the data of the simulation and perform corrections to the angle until it's close enough, did i get that right? (Hope i did :P)
Yes. For each simulated angle compute the miss distance. Then you minimize the miss using Newton's method:
https://en.wikipedia.org/wiki/Newton's_method
For this you need the derivative of the miss(angle) function, which you can get using a finite difference:
https://en.wikipedia.org/wiki/Finite_difference#Relation_with_derivatives
 
  • Like
Likes TheShermanTanker
  • #12
  • Like
Likes TheShermanTanker

Related to Angle required to hit coordinates including air resistance

1. What is the angle required to hit a specific set of coordinates with air resistance?

The angle required to hit a specific set of coordinates with air resistance depends on various factors such as the velocity of the projectile, the direction and strength of the wind, and the distance to the target. It can be calculated using mathematical equations and simulations.

2. How does air resistance affect the angle needed to hit a target?

Air resistance, also known as drag, is a force that opposes the motion of a projectile through the air. It increases as the velocity of the projectile increases. Therefore, it can affect the angle needed to hit a target by changing the trajectory of the projectile and requiring a larger angle to compensate for the drag.

3. Can the angle required to hit a target with air resistance be determined experimentally?

Yes, the angle required to hit a target with air resistance can be determined experimentally by conducting tests with different angles and measuring the distance traveled by the projectile. However, this method may not be as accurate as using mathematical equations and simulations.

4. How can the angle required to hit a target with air resistance be calculated?

The angle required to hit a target with air resistance can be calculated using the range equation, which takes into account the initial velocity, angle, and air resistance. There are also various online calculators and simulation software that can help determine the required angle.

5. Is the angle required to hit a target with air resistance the same for all projectiles?

No, the angle required to hit a target with air resistance can vary for different projectiles depending on their mass, shape, and velocity. For example, a lighter and more aerodynamic projectile may require a smaller angle compared to a heavier and less aerodynamic one to reach the same target with the same air resistance.

Similar threads

Replies
8
Views
1K
Replies
7
Views
6K
Replies
3
Views
16K
  • Engineering and Comp Sci Homework Help
Replies
19
Views
3K
  • Introductory Physics Homework Help
Replies
4
Views
1K
  • Introductory Physics Homework Help
Replies
4
Views
1K
  • Electromagnetism
Replies
4
Views
2K
Replies
2
Views
2K
  • Electromagnetism
Replies
1
Views
2K
Replies
2
Views
4K
Back
Top