Physics/Math help? Variables in Drag Force formula need to be above 0

The formula for drag force can be found anywhere really. FD = 0.5 * ρ * v2 * A * CD; that is, Frictional Drag equals ½ Density * Velocity squared * Area * Drag Coefficient.
Normally this formula is used with the SI-units (kg/m3, m/s, m2). Using the normal units I get ridiculously high numbers, if I use millimeters I get even higher numbers, and adjusting density and drag coefficient just gets me back to what I got with normal units. After some research, I found out that all numbers need to be larger than 1, but when I use millimeters to make the area larger than 1 and adjust all the variables according to that, others become lower (kg/m3 -> g/cm3). Like I said, I suck at math. How should I adjust the units so they’re all above 1 and still give the correct results? Or at least, how do I find out?

Also, if I posted this in the wrong place I apologise. Even if it’s not directly related to Lua, it’s for a Lua script in Garry’s mod, and I figure this should be the place I’ll find people who can answer this question.

Thanks!

I don’t have the mental capacity to figure out what you’re going for, but the only thing i can think of is

[lua]
if (math.abs(value) < 1) then
value = math.abs(value) + (1 - math.abs(value))
end
[/lua]

I wrote this in the reply box, so i could be way wrong here.

The units need to be converted to meters for the formula to work. You need to understand what you’re doing for this kind of stuff to work.

Like sintwins said, SI unit for distance is meters.

Source units are in inches, and I could be wrong on this but I believe 1 source unit = 1 inch. So you have to convert inches to meters.

That’s a truly unpredictable outcome.

@BL00DB4TH & sintwins: I use SI-units to calculate everything, but when actually interacting with the engine I convert them to inches and vice versa.

@IceBreaker88: Isn’t that code basicly just changing the value to 1 if its absolute value is lower than 1? If so, it doesn’t solve my problem, since rounded numbers would give inaccurate results if used in the formula. EDIT: I see what you’re doing now; I miswrote the title, the number doesn’t have to be positive, the absolute number just has to be above 1. Not by force though, that would still give inaccurate results.

@wizardsbane: The formula produces a type of coefficient, so as long as you use units that work with each other, they should give the same (or very close) numbers, even if one unit is smaller than the other. That’s the way I understand it anyway. I apply it to the object like this: V = -G - (FDV)/(MV), where FD is Frictional Drag, V is Velocity, G is gravitational force and M is Mass (in kilograms).

It adds a minimum cap to your value, yes.

Not sure what you were asking, all you asked for was a way to keep your value above 1.

Perhaps i misunderstood.

I guess the issue you’d have with this is assuming the air density of the source engine. Something else?

@wizardsbane: I’m assuming the average air density of air at 25 degrees celsius 100 meters above the water (source: http://130.226.56.171/Support/FAQ/WebHelp/AirDensityTable.htm) is enough to qualify for the source engine’s air density.

@IceBreaker88: You’re right in that I need the values used in the formula to be above 1, but they need to be that natively, not by force. Let’s say the area is 1 cm2, and I use m2 in the formula. The value would be 0.0001, but if I forced the value to be 1 I would get the results for an object with an area of 1 m2 (10000 cm2) instead of 1 cm2, which makes a huge difference in drag force.

This page may be of interest to you (couldn’t find it on the mirrors)
http://webcache.googleusercontent.com/search?q=cache:Dgpu_plOtvcJ:wiki.garrysmod.com/index.php%3Ftitle%3DPhysics%26oldid%3D52740+&cd=1&hl=en&ct=clnk&gl=us

I read a bit about force due to drag in air, and it seems to be the same formula (velocity squared, density, etc is still used), except that the drag force formula is combined with the formula to apply it to the velocity, and the Drag Coefficient is a constant added to the ½-part of “½ Density”, which explains why everything has the same terminal velocity in the source engine. I’m not a mathematician so I don’t know how to express it in a coherent sentence but… basicly, it gives me a little insight, but it doesn’t really help solve my problem :confused:

EDIT: Actually I just tried calculating it, and since the area is still below 1 m2 (thereby crippling the formula) the force due to drag in my case would be 104443 times as strong as the original velocity. So the object would start going in the opposite direction each frame, rising in speed ridiculously much each time.

I’ll just write what the formula looks like in my case (everything in SI-units).
FD = 0.5 * 1.17 * (650 * 650) * 0.025 * 0.35

CD and A is below 1, which cripples the formula (atleast A does, not 100% sure about CD). If I use a smaller unit for A, I have to use smaller units for kg/m3 (density) as well, which puts that variable beneath 1 (changing it to g/cm3). It may be that I should just make density into g/m3 though… Haven’t thought of it, but I’ll try when I wake up properly. Maybe someone more math-oriented can tell me if that’ll work or not before I have, or even find other mistakes I’m making.

Also yes, I’m trying to make small objects go faster than the source engine allows. I’m sure someone can figure out why.

Could you post the code showing how you are trying to implement this and maybe we can give you more help.

I don’t really understand what you’re asking, you need to keep the units in SI units for the formula to work. Also why do you need to keep the value above 1? Isn’t it obvious that if you have an object with a small surface area that it will have a low frictional drag?

Defining constants (SI units):


CD = 0.35    -- Actually the drag coefficient isn't constant, but as far as I can tell it only changes slightly depending on speed and a few other factors. Either way, this is as accurate as I can get since I don't have a usable formula to calculate the drag coefficient.
Caliber = 0.0057
Area = ((Caliber * 1000 / 2) ^ 2 * math.pi) / 1000
Weight = 0.0015
Density = { Air = 1.17 }
Velocity = ply:GetEyeTrace().Normal * 650

This is how I calculate the FD:


FD = 0.5 * Density.Air * (Velocity * Velocity) * Area * CD

I haven’t actually written any code for changing the velocity of the object yet since I know it’ll most likely just crash. And I don’t know why I need to keep it above 1, it’s just a guess. Using those numbers, I get an FD of 2207. And then, using that on the acceleration formula I get a velocity of 1471631. That’s a lot faster than 650 m/s so something must be wrong somewhere… right?

Well firstly I’m not sure exactly what you’re doing but correct me if I’m wrong.

(Caliber * 1000 / 2) ^ 2 * math.pi) / 1000

Here you seem to be trying to find the cross sectional area of the bullet. Which if you are assuming it is spherical would be
(Caliber / 2) * (Caliber / 2) * math.pi
Also as for the velocity, I’m not very familiar with how Gmod handles them, so others may need to comment on this, but I’m pretty sure Gmod doesn’t use SI units, so you will need to make sure that you convert the velocity to metres per second before using it for any calculations.

Actually velocity is set manually in a variable instead of fetched using :GetVelocity(), and m/s is used when putting it into the variable. After that, I calculate the trajectory of the object by making a few traces (making sure I use inches instead of SI units) and set its position at the end of the tick, using inches instead of meters.

And yes, you’re absolutely right about what I’m trying to make with the Caliber :slight_smile: Since the caliber is in millimeters, I first multiply it to be above 1, then I divide it by 2 and multiply it by itself (radius squared) and then by pi, after which I divide it by 1000 again so it won’t have grown 1000 times in size. But I realized now I’m supposed to divide it by 1 000 000, so thanks for getting that to my attention. In fact, maybe that will solve the problem.

EDIT: After running the new variables through the formula I get this:
FD = 2.2059253125
a = 1470.616875
“a” being the new speed of the object (in m/s). So, it still doesn’t work :frowning: Apparently FD needs to be lower than 0.975 (Mass*Velocity) in order for the bullet to slow down at all. Notice any other mistakes I’m doing?

Thanks for the help!

What do you mean that the FD needs to be lower than 0.975 for the bullet to slow down,for any value of FD shouldn’t the bullet slow down and how are you calculating the change in velocity of the bullet ?

d = -G - (FDV)/(MV)

Where G is Gravity (m/s), M is Mass (kg), V is Velocity (m/s), and “d” is the new velocity.

Because M*V = 0.975 (0.0015 * 650 = 0.975), for there to be a deceleration FD has to be lower than 0.975. As I said, FD is a coefficient used to modify existing values, not a measurement of defined units.
Because of that, it would make sense to me that an FD of 2 doubles the speed while an FD of 1 has no change, but because of the formula used to modify the speed (which is the only one I can find for this purpose) it needs to be lower than 0.975. Running the formula with an FD of 0.975, mass of 0.0015 and velocity of 650 results with d = 650 (no change). A lower FD will result in a proportionally lower new velocity.

I haven’t seen that formula before, so I’m not exactly sure about that. But couldn’t you just use F = ma to calculate the new velocity?

Why are you taking into account gravity for horizontal velocity? It has no direct effect on it.

Or, is this vector math here?

I’m sort of mixing velocity as a vector and as the magnitude of the vector. I probably should’ve been more clear about when I do that.
I only use it as the magnitude of the vector when testing the formulas though, so that is more a problem of implementation once it works.

What is F, m and a?

I got the formula for FD from lots of sources, it’s the only formula for calculating friction drag that I can find. I found out how to apply the FD in google’s preview of the book “Physics for Game Programmers” (http://books.google.com/books?id=oVLDoO-V67cC), chapter 5 page 105. Maybe if you read about it there it’ll be easier to understand than my explanations, I only barely understand the formulas anyway ^^’

Also, I’m going abroad from the 6th to 26th, but I’ll try to be as active as I can during that time.