# Apply drag to rotation

This topic is 970 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

ihave a body lets say its liek this both spheres are connected so when i move one other moves too lets say center of mass is hooked so i can only rotate this 'body'

So whenever i apply a force to one sphere the rotation occurs and it produces drag, now how should i apply this drag (i understand that drag will be generated for both spheres)

my code looks like this

for (int i=0; i <num_of_spheres; i++)
{
if (i==0) apply_force_to_this_sphere();

vec3 cog2cob_vec = vectorAB(pos + WORLD_MAT * CENTER_OF_GRAVITY, sphere[i].geometric_center);

vec3 ETorque = cog2cob_vec	*	SPHERE_FORCE;
vec3 EAngAcc = ETorque / EMOI;

vec3 EAngVel = EAngAcc*dt;
vec3 EAngMov = EAngVel*dt;

}


Now i am confused where in the code should i apply drag

should i first calculate the rotation without drag then check for angular velocity and then apply drag force and change angular velocity again?

or should i apply drag to each sphere like



for (int i=0; i <num_of_spheres; i++) {
if (i==0) apply_force_to_this_sphere();

for (int n=0; n < num_of_spheres; n++)
if (i!=n)
{
apply drag to each sphere
}

or

for (int i=0; i <num_of_spheres; i++)
{
vec3 SPHERE_FORCE = vec3(0.0, 0.0,0.0);
if (i==0) apply_force_to_this_sphere(); //SPHERE_FORCE = SPHERE_FORCE + thrust

vec3 cog2cob_vec = vectorAB(pos + WORLD_MAT * CENTER_OF_GRAVITY, sphere[i].geometric_center);

vec3 ETorque = cog2cob_vec	*	(SPHERE_FORCE+drag_for_this_sphere_based_on_angular_vel);
vec3 EAngAcc = ETorque / EMOI;

vec3 EAngVel = EAngAcc*dt;
vec3 EAngMov = EAngVel*dt;

}


thus last example shows that angular vel will change each iteration thus i think it will somehow apply greater drag to other sphere, and since distance from center_of_mass to both spheres in this case is the same it should have the same drag value(not direction but length)

so how do i do it?

##### Share on other sites

I think you're talking about a spherical joint. The idea is to create a constraint that will keep the objects from moving both angular and linearly towards the blue middle point in your picture. (https://github.com/irlanrobson/Bounce/blob/master/Src/Dynamics/Joints/b3SphericalJoint.cpp). Uniquely you would be creating a constraint for both spheres, apply impulses for 1 iteration, and integrate the positions and velocities after.

Edited by Irlan Robson

##### Share on other sites

Thats not quite what i meant i just have a body that is made out of boxes so they represent mass distribution over a body

but you said that i should first apply all forces that rotate (and proceed with rotation) then in next frame add drag (since we have motion (rotation)) to each box depending on angular velocity?

##### Share on other sites

There was an approximate drag equation by Catto from Game Programming Gems 6 where he wrote about buoyancy simulation.

Td = B * m * (V / Vt) * L^2 * w

Td = drag torque

B = angular drag coefficient

V = volume of submerged portion of polyhedron

Vt = total volume of polyhedron

L = approximation of the average width of the polyhedron

w = angular velocity

The interesting thing is that L can actually be the red vector in your original picture. When I implemented this I kept the maximum L value that a particular mesh generated. In the end since this equation is an approximation the choice of L can be considered somewhat an exercise in artistic expression

This equation was written in the context of meshes floating upon water, so V, Vt and L might not be relative to a polyhedron, but maybe spheres like in your example. But I sort of assumed you're asking this for the boat stuff you've been working on.

Edited by Randy Gaul

##### Share on other sites

ok ok ;] but that was not the question i maye simplify my question:

where do i apply drag to rotation:



find_drag_based_on_rotation_vel
calculate rotation and update rotation
repeat

or



for each box
{
claculate rotation for this box, apply drag based on this rotation (box caused that) for all other and this box
}
update angular vel

or



aliens
voodoo

? :/



for normal linear motion i use something like that
calculate drag based on velocity
apply all forces (and drag too)
update position

i dont see how should i proceed with rotation where i have 8 boxes that simulate 1 body.

Edited by WiredCat

##### Share on other sites

If you have 8 boxes representing 1 rigid body, then you should probably only store velocity/mass for the rigid body, not each box. Then you just integrate velocity, apply drag, once each, and done. The term is "compound rigid body" (or aggregate rigid body). Or maybe you meant something else?

Are you wanting to do something like this? CSTk8CPU8AAwYTp.mp4

Edited by Randy Gaul

##### Share on other sites

When integrating the velocity you do use the acceleration (v(t + dt) = v(t) + dt * M^1 * F, w(t + dt) = w(t) + dt * I^1 * T, without gyroscopic into account). I guess Randy meant: Buoyance returns the force and drag torque to apply on the body. Apply those, then use whetever integrator from here on the velocity and position. Clear the accumulated forces and torques and repeat the process.

Edited by Irlan Robson

##### Share on other sites
I do the 'apply drag next frame' thing. Forces put a body in motion. Next frame, for each aerodynamic element attached to the body, i find the local linear velocity at that point (e.g. the linear velocity of each of your spheres is a function of the body's linear/angular velocities anf the sphere's offset from the center of mass) and calculate drag forces. You can look up the drag coefficient for a perfect sphere, most of my stuff operates on rectangles though :)
n.b. this is an approximation that assumes that the spheres are somewhat small. For large spheres, the outside edge would have a high linear velocity while the inside edge would be low... So calculating drag for the whole sphere at once wouldn't quite be correct.

For something like a flight simulator, they'd break each wing up into many smaller pieces to get a better approximation.

##### Share on other sites
Oh yeah, certainly there must be constantly some advanced scenarios in which you can't just rely on forces/velocity changes cumulatively before a physics step depending of the phenomena you want to simulate, such as Hodgman's drag model (using minimizing bouding boxes to approximate an aerodynamic part if I understood correctly I guess). Maybe that was Randy's contextualization. .

##### Share on other sites

ok things get clearer now, just one more thing: lets say for first box there is a drag produced, this drag should be added to linear velocity (attached to center ofthe body aswell right?)

i somehow think i nedd somehow to apply drag made from rotation to linear motion or maybe its totally different thing andi should calculate linear drag of each box

1. 1
2. 2
3. 3
4. 4
Rutin
21
5. 5

• 9
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632938
• Total Posts
3009317
• ### Who's Online (See full list)

There are no registered users currently online

×