last day (15 days later) » 

16:58
0
Q: Is my airspeed calculation code correct?

kj7rrvNot sure if I should ask here, on Drones SE, or on Code Review SE. Is my Python code for calculating airspeed given ground speed, ground direction, wind speed, and direction from which the wind is blowing correct? It takes directions in degrees, and the speeds can be in any units as long as they'...

Jim
Jim
This kind of question should be broken into two parts. First check the derivation of the equation itself. I.e., the physics and math portion. Once you are sure the math is right, then focus on whether the code faithfully reproduces the calculation. We shouldn't have to derive the equation ourselves just to check your work. :-)
@Jim do abelenky's edits fix that?
@757toga would it be on topic on Code Review even though the formula itself is as important as the code?
That's why I made them.... trying to make the question as clear as I can. Apologies if the edits changed the question too much.
@Jim the direction from which it's blowing
@abelenky no, your edits are fine, thank you! I should have added the formulas.
The python code implements exactly what you've written. Use math.radians(x) instead of π/180. Why there's a -180 in your equation? Maybe a quick plot would help understanding it.
16:58
@sophit it's supposed to work with the assumption that the plane is flying at 0°, and to account for differences. θ is the angle between an imaginary line extending from the plane and a line made by the wind. The -180 is so it takes the direction from which the wind is coming rather than the direction in which it is going.
Oh wait, actually, I don't want the -180 because I want it reversed because I'm actually subtracting the vectors.
Et voilà, you're welcome 👍
The way to verify your code is to test it extensively. If your idea of testing is to put the code in front of a bunch of strangers and ask them what they think, I won't trust it anywhere my feet are off the ground.
Do not forget that, since you are summing up flight speed and wind speed, then wind is positive when investing the aircraft from nose to tail.
@sophit since it takes the direction from which the wind is coming, there is an "implied" 180° rotation which turns it into a subtraction, which is what I need. Ground velocity = air velocity + wind velocity, so air velocity= ground velocity - wind velocity.
@fab that does the opposite of what I need. I'm trying to find the airspeed of a model plane given the speed and direction of the plane from GPS and the wind speed and direction from an external source.
fab
fab
16:58
Yes you would have to invert that equation.
@fab does that equation do anything that this one doesn't?
Mmh, I'm still not happy with the math. Let's suppose that both wind and airplane are heading at 0°, then θ=0 and Vair=Vground+Vwind but it should be Vair=Vground-Vwind.
@sophit find_airspeed(100, 0, 100, 180) returns 1.2246467991473532e-14, basically zero. find_airspeed(100, 0, 100, 0) returns 200.
In my opinion that's confusing since when you set both heading at 0° then wind and airplane are actually moving in opposite directions. Anyway the important thing is that you are comfortable with your convention 🖖
 
3 hours later…
19:49
The chat UI is indeed not very mobile friendly, but it does work. (Posted from a mobile phone)

last day (15 days later) »