Sign in to follow this  

Apply drag to rotation

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

If you intended to correct an error in the post then please contact us.

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'

 

 

bodym.png

 

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;

vLocalAngularMoment = vLocalAngularMoment + EAngMov*RAD_TO_DEG;

}

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;

vLocalAngularMoment = vLocalAngularMoment + EAngMov*RAD_TO_DEG;

}

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 this post


Link to post
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 this post


Link to post
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

 

 

bodym2.png

 

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 this post


Link to post
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 smile.png

 

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 this post


Link to post
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 







abrakadabra
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 this post


Link to post
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 this post


Link to post
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. smile.png

Edited by Irlan Robson

Share this post


Link to post
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 this post


Link to post
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. smile.png.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
If there are multiple aerodynamic elements attached to the rigid body, then each will be applying a drag force a a particular local offset / position relative the the center of mass.

When applying these not-at-center forces, a force and a torque is applied to the body.

Share this post


Link to post
Share on other sites

so actually some force is distributed to center of mass as linear force for whole body, how do i calculate that then? (i mean when i apply not-at-center force, ok i have a torque but what about linear force for the body (where i apply that to the center of mass of the body)

Share this post


Link to post
Share on other sites

Fb += F

Tb += r x F

 

This is how we apply a force to a rigid body at non-center of mass, were Fb is force of body, and Tb is torque of body, F is force we are apply, and r as at this radius vector from center of mass. r = Point - COM (center of mass). A point applied to non-COM will generate more energy than one applied to COM due to the definition of work (force * distance). So, we just sum the linear forces, and sum r x F torques. Does this make sense?

 

More in-depth read: https://www.cs.cmu.edu/~baraff/sigcourse/notesd1.pdf

Edited by Randy Gaul

Share this post


Link to post
Share on other sites

i am quite surprised that from what you have shown here whenever i 'kick' a penicl with a finger on a tip of it it will add same linear force as i would 'kick' it in the center , i though applying a force on one end of body will produce less linear force applied to its center, than applying the same force to its center

 

 

Moreover i just removed some great amount of comments from the physics function i wrote long time ago and i do exactly the same thing (add the same force) :X

Edited by WiredCat

Share this post


Link to post
Share on other sites

i am quite surprised that from what you have shown here whenever i 'kick' a penicl with a finger on a tip of it it will add same linear force as i would 'kick' it in the center , i though applying a force on one end of body will produce less linear force applied to its center, than applying the same force to its center

I'm just guessing, but when you kick something you're accelerating it over a period of time (many ' frames'). When you kick the end, it rotates out of the way, so that your foot isn't accelerating it for the same length of time any more. Kicking the center ensures it stays in contact with you're foot. Also, as it rotates, the contact surface becomes angled so your foot starts pushing it in the wrong direction.

Share this post


Link to post
Share on other sites

I want to ask another thing when calculating drag of a body (rotational part) when i am counting through lets name that boxes, the actual velocity of the body is linear vel + rotational vel right?

 

and rotational vel since its in radians in my case i need to create a vector from actual box position = A to after returnNewPos(box_pos, rot_vel * deltaT) = B

 

 

the actual drag vector will be: Normalize( -(B-A) ); ?

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this