| 08-06-2007, 12:28 AM | #1 |
Im working on a small portable projectile system, and I need a simple way to emulate gravity / drag. I would try to make it myself but my highest completed math is Algebra 1. If someone could help me through this dilemma i would be very grateful. |
| 08-06-2007, 01:10 AM | #2 |
gravity is the force that pulls something down expressed as: G=mg m=mass g=9.81 --- Anyway that was just theory part... to make it work just give unit a speed in Z direction, and then substract from this speed with some value for every periodic time that u choose and feels it looks nice. And of course u must move this unit with this speed Z every periodic at the same time. About drag i have not read about it yet so... |
| 08-06-2007, 01:28 AM | #3 |
i know, i have a gravity system in place, I just want to know if i should use an equation or not. And about the drag, i have no idea how to emulate that. |
| 08-06-2007, 01:34 AM | #4 |
Gravity typically corresponds to a constant acceleration. Drag typically refers to a slow down proportional to velocity. For this case the equations of motions can be solved explicitly. k: drag / mass g: gravitational acceleration v0: initial velocity x0: initial position t: time v0 -> g/k + e^(-kt)(v0 - g/k) x0 -> x0 + v0/k + (g/k)(t - 1/k) + e^(-kt)(g/k^2 - v0/k) for drag proportional to v^2: v0 -> sqrt(g/k) tanh(sqrt(gk)t + arctanh(sqrt(k/g)v0)) x0 -> Analytic solution exists, but is too expensive to compute, best to numerically integrate Since you'll be taking small time steps anyway, you might as well use numerical approximations. Simple second order formulas: Linear drag: v0 -> v0 + (g-kv0)t + (kv0 - g)kt^2/2 x0 -> x0 + v0t + (g-kv0)t^2/2 Quadratic drag: v0 -> v0 + (g - kv0^2)t + (v0^2k^2-gk)v0t^2 x0 -> x0 + v0t + (g-kv0^2)t^2/2 Quite a lot of algebra went on here so it's quite possible I fucked up somewhere. |
| 08-06-2007, 02:15 AM | #5 |
.... uhhh... i think ill use quadratic drag personally... if i acutally really understood what was going on...for gravity, i have a little quadratic equation i worked up... would this work: X = Times Ran IH = Initial Height IFv = Initial Vertical Force Fg = Gravimetric Force Z = Hieght TS = Time Per Step Z = IH + ((((IH - Fg*X)*X) - IH - Fg*X)*TS) would that work as a viable gravity quadratic. It made a nice arc when i graphed it on a calculator.. but i have no idea if it would actually work well as a gravity emulator.............. |
| 08-06-2007, 02:59 AM | #6 |
Your particle starts with velocity vector v and position vector x at time t. You use this information to estimate where it will be at t + tstep. To use quadratic drag, you update v by replacing it with the formula. I left out some of the vector notation; + indicates vector addition, - vector subtraction which are just component by component addition/subtraction and v^2 means v *length(v). g, v and x are vectors. In general k could be a rank 2 tensor (aka matrix), but for your application just a number will suffice. |
| 08-06-2007, 07:13 PM | #7 |
if i know vectors as well as i probably should... then is vector V = {5,6,7} and vector 2 = {1,2,3} vector V- vector2 = {4,4,4} right? and would t be time already spent in flight? |
| 08-07-2007, 01:36 AM | #8 |
Turns out 'vector' is a very general concept for which you can define all sorts of crazy addition rules. For your purpose though yes, that's the right rule. t is your timer period |
| 08-07-2007, 02:15 AM | #9 | |
ok, wait a sec Quote:
if k uses drag, and k is used in drag, wouldnt that create an infinite depency loop??? and sasy my struct is called every .01 seconds, would t then equal .01? |
| 08-07-2007, 02:20 AM | #10 |
Let's say we have k1 and k2. k1 is the force drag and k2 is the acceleration drag. They're related by k2 = k1/mass. .01s: Try it and see. |
| 08-07-2007, 02:33 AM | #11 |
so how are force drag and accelation drag different? Im sorry, ive never done this sorta stuff before. |
| 08-07-2007, 04:08 AM | #12 | |
Quote:
When doing physics simulations, the easiest method is Euler's: - Calculate current accelerations/forces (gravity, drag, etc) - Update speed (v = v + a*t) - Update position (p = p + v*t + a*t*t/2) - Repeat http://en.wikipedia.org/wiki/Euler_method |
| 08-07-2007, 08:23 AM | #13 |
They are talking about calculating drag acceleration.. That's the whole issue here. Pipedream translation: Force drag is the drag's force. Acceleration drag is the drag's acceleration. F = m*a force drag = accel drag * m accel drag = force drag / m You calculate the force first, but that's of no good to you until you divide it by mass and get the actual acceleration of that iteration. By the way, if you mess around with a drag constant, maybe you could get it to look 'ok' and use the constant acceleration formula. It won't be correct, but it will be a lot easier to understand. Just an idea. |
| 08-07-2007, 11:43 PM | #14 |
so, drag force is how object velocity / density of the air? That makes sense. |
| 08-08-2007, 08:47 AM | #15 | ||
Hm..actually air resistance is also depentant on the surface of the object. The only thing my formula does is take your calculated drag force and turn it into acceleration. I believe pipe dream's drag is more drag in general, not air resistance. fyi, I think you already got this part... The reason pipedream said this: Quote:
is because you said this: Quote:
He specified the 2 k's. One of them is the dragforce, the other is the dragacceleration. On a different note.. since it will be used for air resistance, isn't it better to use Fwind = r*cw*A*vwind² where: Fwind = wind's force r = density of air in kg/m³ cw = dimensionless coefficient of wind resistance (you'll have to guess) A = reference surface of the object (you'll just have to guess on this one..) vwind = wind's velocity Big problem with this: This formula only holds when there is no wind velocity (only the velocity the object makes). If both the object and the wind move, they will, in all probability, move in different directions and you would have to take the vectorsum due to motion of the object and the 'true wind' instead of the vwind. However, since cw and A only apply to normal airflow to the front of the object, this will pose a problem. A good description of air resistance which is similar to reality is not entirely simple. After that it's iteration heaven, allowing you to use constant acceleration formulas over a small period of time. Dunno, what do you think? |
