angular velocity, runge kutta

Started by
3 comments, last by coke_baby 20 years, 5 months ago
hi, i've been having a look through this forum and am a *tad* intimidated by some of the threads i've read, but here goes anyway. please forgive my naivity in some respects, i have covered this stuff before at uni but it obviously didn't stick too well =) I'm trying to find a reasonable solution for angular velocity. I have a simple vehicle in an environment with no collision detection or gravity, so in a sense i'm working in 2D. I am using 3D vectors though as at some point i will want to add to my model. Anyway, my problem is that I've been using euler for solving my angular velocity using the following simple process (theta is the rotation around the yaxis)- 1) get a torque vector which is the cross product of a force acting due to wheel angle and a distance vector from the center of mass to the wheel 2) scale this vector by a constant ( equivalent to inertia i guess) and multiply the result by dt , add to the current rotational velocity vector 3) take the length of the rotational velocity vector and multiply by dt to get the change in theta this has been giving me strange results which i thought might be due to the method of integration i've been using, so I thought i'd give runge-kutta a shot. however, i'm having problems applying the algorthm to my problem. for instance, the first line of in iteratino looks something like this: d1 = Hf(Tn, Xn) from what i can gather this is equivalent to the euler method (?). I'm assuming that Xn is angular velocity, as integrating that should give me theta. I'm basically having trouble with exactly what the function Hf is, as I'm working off angular acceleration = torque/Inertia I don't see any function of Xn, so is it ok to use that ratio? my code is below, i pass it the rotational velocity vector: Vector3D SolveVector3DRK(Vector3D Xn) { float h = dt; float k = h/2.0f; Vector3D d1, d2, d3, d4; d1 = Xn + (this->torque/(float)(mass/10)) * dt; d2 = (Xn + d1/2) + (this->torque/(float)(mass) * (dt + k); d3 = (Xn + d2/2) + (this->torque/(float)(mass) * (dt + k); d4 = (Xn + d3) + (this->torque/(float)(mass/10)) * (dt + h); Xn += (d1 + (d2*2) + (d3*2) + d4)*(1.0f/6.0f); return Xn; } but it's flying off the wall, just increasing away until i've got NAN's oll over the show. Anyone got any ideas? Perhaps I should be integrating the rotational acceleration - I really am lost. I'd appreciate youkind words without flames too - i did a search in this forum for a similar topic but only found one that was using quarternions (which by the way descended into chaos =) well, thanks for any help you can offer, ta! [edited by - coke_baby on November 11, 2003 5:23:39 PM]
Advertisement
or- is there actually any point in using runge-kutta if my acceleration is always going to be (torque/some constant)
Runge Kutta is better for fluctuating framerates, whilst Euler goes haywire with some systems under varying framerates, so I guess the question back at you is... how stable do you want your system and what performance are you willing to sacrifice for it?

As for the actual angular velocity thing. When a collision occurs on your car, perform an instantaneous impulse upon the car applied at a certain position with respect to the car. The impulse is applied over a certain time frame and merely affects the linear velocity as well as the rotational velocity of the car.

Don''t store the angular acceleration because that should be attributed to an outside force acting on the car (eg. another car or a wall)

So you basically want to do something like this (ripped straight from www.racer.nl :: technical documents :: physics tips)

Normally, Euler looks like this:


F=CalcForce();
acc=F/m;
pos+=vel*t;
vel+=acc*t;

This is Runge Kutta (order 2) based on the taylor series:

F=CalcForce();
acc=F/m;
pos+=vel*t+0.5*acc*t*t;
vel+=acc*t;

You apply these integration steps to both [angle, angular velocity, angular force] and [position, linear velocity, linear force] so that your code looks something like this:

car.angle += car.angularvelocity * dt + (0.5f * angularimpulse * dt * dt);car.angularvelocity += angularimpulse * dt;car.position += car.velocity * dt + (0.5f * acceleration * dt * dt);car.velocity += acceleration * dt;


now the only difficulty lies in calculating angular force as well as linear force. Angular force is a function of the external force applied to a position on the car-body taking into account the current bodies orientation and it''s centre of mass.

Good luck.


do unto others... and then run like hell.
quote:Original post by FReY
Runge Kutta is better for fluctuating framerates, whilst Euler goes haywire with some systems under varying framerates, so I guess the question back at you is... how stable do you want your system and what performance are you willing to sacrifice for it?

As for the actual angular velocity thing. When a collision occurs on your car, perform an instantaneous impulse upon the car applied at a certain position with respect to the car. The impulse is applied over a certain time frame and merely affects the linear velocity as well as the rotational velocity of the car.

Don''t store the angular acceleration because that should be attributed to an outside force acting on the car (eg. another car or a wall)

So you basically want to do something like this (ripped straight from www.racer.nl :: technical documents :: physics tips)

Normally, Euler looks like this:


F=CalcForce();
acc=F/m;
pos+=vel*t;
vel+=acc*t;

This is Runge Kutta (order 2) based on the taylor series:

F=CalcForce();
acc=F/m;
pos+=vel*t+0.5*acc*t*t;
vel+=acc*t;

You apply these integration steps to both [angle, angular velocity, angular force] and [position, linear velocity, linear force] so that your code looks something like this:

car.angle += car.angularvelocity * dt + (0.5f * angularimpulse * dt * dt);car.angularvelocity += angularimpulse * dt;car.position += car.velocity * dt + (0.5f * acceleration * dt * dt);car.velocity += acceleration * dt;


now the only difficulty lies in calculating angular force as well as linear force. Angular force is a function of the external force applied to a position on the car-body taking into account the current bodies orientation and it''s centre of mass.

Good luck.




is that the Runge-Kutta? Looks like a higher order Euler integration.

There is also the verlet integration, which works well under constrains.



- Oli.



Home

rigid body demo

Simple Z-fail Stencil shadows demo

Sphere/cube/Triangle Collision And Physics demo



Everything is better with Metal.

thanks , FReY - i''ve finally figured what my problem was, and turns out my euler was ok. I''m not even up to collisions yet, the angular acceleration i''m talking about is the cars rotation as it turns a corner - the equations looked the same tho, as instead of using an impulse (as in a collision), i''m using the force from the wheels, which is more constant.

in case anyone''s interested, my oscillations were due to the way i was rotating the car - i was using the angular velocity vector as my axis of rotation, so when it changed direction (ie the angular velocity passes through zero), the car was getting rotated in the opposite direction - say it''s ''angle of attack'' was 35, and the angular velocity changed from +ve to -ve, then the new angle of attack would be -(35+ change in theta). if that makes sense. so i''m checking the direction of the angular velocity vector now and making allowances for that. not so elegant, but it works.

thanks for the info on runge-kutta too, i''ll be using that.
thanks again!

This topic is closed to new replies.

Advertisement