Apply torque at a position different than the body center

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Apply torque at a position different than the body center

Postby agsh » Fri Apr 17, 2009 1:31 pm

Hello everybody,

I'm getting in to a mess trying to make a flight simulator. Hope you can help me. My problem is that I have to apply some forces at different points of a wing and I don't know when shoud I use addForce, addGlobalForce,addLocalForce... Let suppose the following situation.
Image
I suppose the forces can be applied to the body centre because they do not generate torques, so the following situation is equivalent to the former and I shoud use addForce. Is this corect?
Image
But the aerodynamic torque, by definition, shoud by applied at the aerodynamic centre. How can I apply the torque at a position different than the body center? :?

Edit1: A solution could consists on modifying the mesh models to make both the aerodynamic centre and body centre coincide, but the problem is that, in some extreme situations, the position of the aerodynamic centre could change.

Thanks in advance and I apologize for my english.

Regards,

Alberto
agsh
 
Posts: 11
Joined: Fri Apr 17, 2009 12:26 pm

Re: Apply torque at a position different than the body center

Postby JernejL » Fri Apr 17, 2009 6:21 pm

You can "add local point force" at any point on the mesh, these functions may come in handy for you:

// retrieves body's velocity at specific point in global space
function GetPointGlobalVelocity(const body: PNewtonBody; Point: TVector): TVector;
var
velocity, omega: TVector;
begin
NewtonBodyGetVelocity(body, @velocity);
NewtonBodyGetOmega(body, @omega);

Result := VectorAdd(velocity, VectorCrossProduct(omega, point));
end;

// retrieves body's velocity at specific point in local space
function GetPointLocalVelocity(const body: PNewtonBody; Point: TVector): TVector;
var
bodymatrix: Tmatrix;
begin
NewtonBodyGetMatrix(body, @bodymatrix);
Result := GetPointGlobalVelocity(body, MatrixRotateVector(Point, bodymatrix));
Result := MatrixUNRotateVector(Result, bodymatrix);
end;

// adds force to body at a specified point in global space
procedure AddPointGlobalForce(const body: PNewtonBody; PrevBodyMatrix: pointer; Force, Point: TVector);
var
GlobalForce: TVector;
bodymatrix: Tmatrix;
Torque: TVector;
begin

if PrevBodyMatrix = nil then
NewtonBodyGetMatrix(body, @bodymatrix)
else
move(PrevBodyMatrix^, bodymatrix, sizeof(Tmatrix));

GlobalForce[0] := Point[0] - bodymatrix[3][0];
GlobalForce[1] := Point[1] - bodymatrix[3][1];
GlobalForce[2] := Point[2] - bodymatrix[3][2];

Torque := VectorCrossProduct(GlobalForce, Force);

NewtonBodyAddForce(body, @Force[0]);
NewtonBodyAddTorque(body, @Torque[0]);
end;

// adds force to body at a specified point in local space
procedure AddPointLocalForce(const body: PNewtonBody; Force, Point: TVector);
var
GlobalForce, GlobalPoint: TVector;
bodymatrix: Tmatrix;
begin
NewtonBodyGetMatrix(body, @bodymatrix);

GlobalForce := MatrixRotateVector(Force, bodymatrix);
GlobalPoint := MatrixTransformVector(Point, bodymatrix);

AddPointGlobalForce(body, @bodymatrix, GlobalForce, GlobalPoint);
end;


// retrieves body's omega in local space
function GetLocalOmega(const body: PNewtonBody): TVector;
var
bodymatrix: Tmatrix;
omega: TVector;
begin
NewtonBodyGetMatrix(body, @bodymatrix);
NewtonBodyGetOmega(body, @omega[0]);
Result := MatrixunRotateVector(omega, bodymatrix);
end;


you can also set the body centre matrix (using offsetmatrix), but that's only when you have to change body center during creation, it's not intended to be changed later (i think)
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Apply torque at a position different than the body center

Postby Julio Jerez » Sun Apr 19, 2009 9:55 am

there is also teh funtion NewtonBodytSetCenterOfmass, teh can be use on real time to chen eteh center of gravity, of a body.
I beleive it is the function you need to repruduce every thing shown on the free force diagram.

The SDK provide all teh nessesary to reproduc the wing behavoir you are describing, by using the funtion I how you plus the method delfi shows for applying the forces and the torques.

basically you can add all the forces usin NetwopnBodyAddForces,
then calculate all the torques either in the local body (in thing easier) and rotated then to grabal space before adding it to the body.

Remember all force and torque are in global space, so if you calculate then in the local space of the wings, you need to rotate then to global space before to add then to the body.
This is a common mistale many people made.

It should be quite straightforward to implement an airplane with the SDK
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Apply torque at a position different than the body center

Postby JernejL » Sun Apr 19, 2009 3:58 pm

Julio, i can use NewtonBodytSetCenterOfmass at runtime as much as i want during say forcetorque callback? this affects also functions like setomega, setforce, addforce, addtorque, etc..?
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Apply torque at a position different than the body center

Postby agsh » Sun Apr 19, 2009 6:15 pm

Many thanks for your answers!
Delfi wrote:Julio, i can use NewtonBodytSetCenterOfmass at runtime as much as i want during say forcetorque callback? this affects also functions like setomega, setforce, addforce, addtorque, etc..?

I think this is basically what I'm messed up with. This is what I tried to use first but I think it fails because I use the function addGloblalForce instead of addForce to add gravity force, resulting in a torque (the torque in function addGlobalForce is calculated with respect to the center of the body, not the center of mass, isn't it?). I'm going to modify my code and i'll tell you the result. :)

Alberto
agsh
 
Posts: 11
Joined: Fri Apr 17, 2009 12:26 pm

Re: Apply torque at a position different than the body center

Postby Auradrummer » Tue Apr 21, 2009 2:07 pm

Alberto,

I made something like this you want. But, to apply this force I made the calculation of the torque.

This can be calculated applying a torque resulting of the distance of the point where the force is applyed from the Center of mass. The result was good.
Developing a racing game.
Auradrummer
 
Posts: 132
Joined: Sat May 17, 2008 9:17 am

Re: Apply torque at a position different than the body center

Postby agsh » Mon Apr 27, 2009 11:15 am

Many thanks for the info Auradrummer but I think you don't understand what exactly my problem is. I know that a force not applied at the centre of mass results in a torque (this is what helper function addGlobalForce does). What I don't know is how can I apply a torque, not a force, at any point different than the centre of mass. I even don't know if I asking something stupid :oops: . Maybe it doesn't have sense or it doesn't matter where I apply the torque.

On the other hand, I've been doing some test and I can confirm that (as expected :oops: ) the forces are appied to the body at its center of gravity, not at its body center as I though. Even when the center of mass is modified with the function NewtonBodytSetCenterOfmass. I suppose the torques are applied to the same point, so... Can I apply the forces, change the center of gravity to the aerodynamic center, apply the torque, and reset the center of gravity in the force callback? I'm convinced this won't work because the internal calculations are performed once the force callback has been called, but it probably describes better my problem.

Thanks a lot for your help and I apologize for my english.

Alberto
agsh
 
Posts: 11
Joined: Fri Apr 17, 2009 12:26 pm

Re: Apply torque at a position different than the body center

Postby JoeWright » Mon Apr 27, 2009 12:13 pm

Code: Select all
void BodyPart::AddTemporaryGlobalTorque(dVector kPoint, dVector kAxis, float kTorque)
{
   dVector body_centre=GetGlobalPointFromLocal(dVector(0.0f,0.0f,0.0f));
   dVector R=body_centre-kPoint-kAxis.Scale(((body_centre-kPoint) % kAxis)/(kAxis.GetLengthSquared()));
   dVector norm_axis(kAxis.Normalise());
   if (R.GetLength()==0.0f)
   {
      norm_axis=norm_axis.Scale(kTorque);
      AddTemporaryTorque(norm_axis);
      return;
   }
   dVector In;
   In=mInertiaTensor.TransformVector(norm_axis);
   float inertia=In % norm_axis;
   float local_torque=kTorque*inertia/(inertia+mMass*R.GetLengthSquared());

   dVector force=(norm_axis * R.Normalise()).Scale((kTorque-local_torque)/R.GetLength());
   AddTemporaryForce(force);
   norm_axis=norm_axis.Scale(local_torque);
   AddTemporaryTorque(norm_axis);
JoeWright
 
Posts: 69
Joined: Sat Apr 30, 2005 1:42 pm

Re: Apply torque at a position different than the body center

Postby agsh » Wed Apr 29, 2009 11:09 am

Muny thanks for your answer JoeWright.

I've been triying to figure it out but could you please tell me what % means? Maybe the vector cross product? Do you know where can I find a more detailed explanation?

Alberto
agsh
 
Posts: 11
Joined: Fri Apr 17, 2009 12:26 pm

Re: Apply torque at a position different than the body center

Postby ulao » Wed Apr 29, 2009 11:31 am

its a modular operation.

370 % 360 = 10
or
730 * 360 = 10

;)
ulao
 
Posts: 9
Joined: Tue Apr 28, 2009 9:27 am

Re: Apply torque at a position different than the body center

Postby agsh » Wed Apr 29, 2009 12:44 pm

ulao wrote:its a modular operation.

370 % 360 = 10
or
730 * 360 = 10

;)


Thanks Ulao but... How do you perform the module operation with vectors?

(10,20,30) % (20,30,40) = ?
agsh
 
Posts: 11
Joined: Fri Apr 17, 2009 12:26 pm

Re: Apply torque at a position different than the body center

Postby ulao » Wed Apr 29, 2009 1:34 pm

I see what you mean, in the example above he is moding a vector. Have to think about that one.

My guess is that it just mod's each component.


vector (5, 3, 2) % 2 = (1, 1, 0)
ulao
 
Posts: 9
Joined: Tue Apr 28, 2009 9:27 am

Re: Apply torque at a position different than the body center

Postby Julio Jerez » Wed Apr 29, 2009 6:11 pm

% is an overload operator for dot product.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 19 guests

cron