# Calculating relative velocity with wind speed?

Discussion in 'Physics' started by Gibbonuk, Oct 14, 2019.

1. ### Gibbonuk

Joined:
Dec 10, 2013
Posts:
162
Hi, I have some simple flight dynamics working, but i want to introduce wind to my equations.

Adding it as a force on the rigid is simple, however my lift/drag equations uses only rigid velocities not taking into account any wind velocities.

I thought it would be quite trivial at first (i'm sure it probably is) but i just cant seem to wrap my head around it.

I have a wind direction and magnitude. How do i correctly get the airspeed or rather the wind speed on the rigid at all angles? For example, if its side on wind (cross wind) then the force will be having an effect on the plane, but in terms of lift on the wings it would be very little.

I've looked at this for so long now, my brain has gone.

Thanks

2. ### Maeslezo

Joined:
Jun 16, 2015
Posts:
118
Drag Force calculation seems trivial but it is not.

You can make it easy or complicated. There are so many formulas out there for this, but let use this one:
Force = 0.5*density*wind_speed^2*DragCoefficient*Area
1. Density
1. Here, you can use a fixed value, or in case of aireplanes, you probably should use a density relative to the height
2. Wind_Speed.
1. If you have wind direction and magnitud, I understand that in your case, wind_speed = wind_direction*magnitud
2. How do you square a vector? wind_speed^2 = wind_speed.magitude*wind_speed
3. The resultant force will be in the direction of the wind, so you only need to do airplaneRigidbody.AddForce(force), no matters the rotation of the airplane
3. DragCoefficient. Here is where things get complicated
1. Normally, drag coefficient is only a value, but this isn't true. In my opinion, it should has at least 3 values, one for each axis. An object could be very aerodynamic in one axis but not in other
2. If you use one value, just multiply by dragcoefficient
3. If you decided to use a dragCoefficient for each axis, dracgCoefficient = new Vector3(lateral_drag, vertical_drag, longitudinal_drag)
1. First, transform the direction to localForce. LocalForce = rb.Transform.InverseTransformVector(Force)
2. Now you have the force in local coordinates. Lets multiply each force component by its drag. We can do this with Scale. LocalForce = Vector3.Scale(LocalForce, dragCoefficient)
3. Don't forget to transform the Force again to world coordinates. Force = rb.TransformVector(LocalForce)
4. Area. Here is when the real party starts
1. The area in the formula is the projected area
2. Calculating the projected area is not trivial at all. Recalculating the projection matrix, convex hull for recovering the points, calculating the area of an irregular polygon, etc
3. The "easy" approach is similar to the drag coefficient
1. For example, imagine you define the area as Area = new Vector3(lateral_area, height_area, front_area), so the idea is to transform the wind to local coordinates, so each area component is rescaled based on the wind direction
2. local_wind_direction = rb.Transform.InverseTransformVector(wind_direction). Now you have the wind in local coordinates
3. Notice I am using wind_direction instead of wind_speed, because we need an unit vector
4. scaled_area = Vector3.Scale(Area,local_wind_direction)
5. approximated_projected_area = scaled_area.x + scaled_area.y + scaled_area.z
I am aware it could be pretty messy, I hope it helps

3. ### Gibbonuk

Joined:
Dec 10, 2013
Posts:
162
Thank you for this, some good points for me to go try. reading back at my post I probably should have gone into more detail, so I am thankful you even replied.

Just incase you can help further based on my current workings. I am calculating the lift/drag for each airfoil using the standard equations.

Lift = 0.5*density*localVelocity^2*DragCoefficient*Area
Drag = 0.5*density*localVelocity^2*DragCoefficient*Area

My Cl & Cd come from curves which I setup and I apply all my forces at each airfoil point (apart from fuselarge which i apply at COM)

And with all the correct params everything flies really well.

So now i am trying to add wind, from my understanding this will be 2 parts to wind, the force its self acting on the plane (an additonal force which will slow down or speed up the ground speed) and then there is the actual airspeed or total velocity over the wing (wind velocity and rigid velocity). So I assume in my Lift and Drag where i am using the rigidbody.localVelocity, i also need to add the windspeed velocity too, which will either increase or decrease lift depending on direction (into wind or downwind)?

So there where i am and what I have been doing, trying to add the wind velocity and body velocity together purely for the lift/drag equations, THEN adding the wind force to the plane. I am getting mixed results!

4. ### SparrowsNest

Joined:
Apr 6, 2017
Posts:
1,933
If you're using the local rigidbody velocity you'll need to convert the wind from the world space (that I assume the it is in) and add the two together.
Code (CSharp):
1. Vector3 baseVelocity = rigidbody.velocity;
2. Vector3 windVelocity = windMap.GetVelocity(rigidbody.position); //or however you get the wind velocity
3. Vector3 translatedWindVelocity = transform.InverseTransformVector(windVelocity);
4. Vector3 finalVelocity = baseVelocity + translatedWindVelocity;
Or simply..
Code (CSharp):
1.
2. Vector3 finalVelocity = rigidbody.velocity+ transform.InverseTransformVector(windMap.GetVelocity(rigidbody.position));
and plug "finalVelocity" into your current equation.

to add the other force acting on the plane either a simple case of just adding a force to the body in the direction and magnitude of the wind,
or if you wanna get a little more fancy make the force relative to the surfaces, but that's a bit more math then i'm comfortable with.

unityunity