How to get the rotating velocity for a hingeConstraint

User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

How to get the rotating velocity for a hingeConstraint

Post by Dr.Shepherd »

Hi, all, just to ask how to get the rotating velocity for a hingeConstraint ?

There seems to be only

Code: Select all

btScalar 	getHingeAngle ()
btScalar 	getMotorTargetVelosity ()
Definitely we can calculate the velocity given the angles and time interval between two steps. Is there any other method that is already implemented in Bullet but I didn't notice, or it is wrong to calculate this variable so no need to implement it ?

If no response, I will calculate the velocity with the angle difference and time interval.

Cheers ! Open to discussions !
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: How to get the rotating velocity for a hingeConstraint

Post by Dirk Gregorius »

It is simply dot(omega2 - omega1, axis)
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: How to get the rotating velocity for a hingeConstraint

Post by Dr.Shepherd »

Dirk Gregorius wrote:It is simply dot(omega2 - omega1, axis)
Hi, Dirk, Would you please explain a bit more?

Does omega1, and omega 2 refer to the angular velocity of two objects ?

I don't quite understand the physical principles.
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: How to get the rotating velocity for a hingeConstraint

Post by Dirk Gregorius »

Sorry, Omega is the angular velocity of the attached bodies. And "axis" is the hinge axis. So in pseudo code it looks something like this:

Vector3 DeltaOmega = Body2->GetAngularVelocity() - Body1->GetAngularVelocity();
float Speed = dot( DeltaOmega, Joint->GetHingeAxis() );

Make sure that the hinge axis is in world coordinates when you get it from the joint, but I guess Bullet will take care of this.

HTH,
-Dirk
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: How to get the rotating velocity for a hingeConstraint

Post by Dr.Shepherd »

Mmm...

It really takes me some while to figure out how this formula works, finally I got a rough idea of what's going on. It is like projecting the difference of angular velocity of these two objects onto the hinge axis. Correct me if I am wrong.

I hate the rotation multiplication, I like Linear Stuff !

Cheers Man!
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: How to get the rotating velocity for a hingeConstraint

Post by Dirk Gregorius »

Well, DeltaOmega is the relative angular velocity between both bodies. Then you project this velocity onto the hinge axis. No rocket science :)

Note that depending on how the constraint is setup you might use Omega1 - Omega2. If the constraint setup corresponds to my formula above you know that a negative projected velocity is driving towards the lower limit and the positive projective angular velocity drives toward the upper limit. From the back of my had I remember that e.g. the ODE (in case you use dQuickstep inside Bullet) uses Omega1 - Omega2. You can simply find this out experimentally with two bodies connected by a hinge and one fixed if you cannot find it in the code.

I personally prefer it the other way around so I can interpret the first body as the parent. But this is a matter of personal preference.
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: How to get the rotating velocity for a hingeConstraint

Post by Dr.Shepherd »

Just to be more clear for others, because I just figured out the exact detail of it.

How to get the world coordinates for the Hinge Rotating axis?

If we set up the hinge constraint using:

Code: Select all

btHingeConstraint(*pBodyA, *pBodyB, pivotA, pivotB, axisA, axisB);
So the world coordinate for this rotating axis is simply the multiplication of the global transformation of pBodyA and axisA (Similarly, it is equal to global transformation of pBodyB * axisB)

If we set up the hinge constraint using:

Code: Select all

btHingeConstraint(*pBodyA, *pBodyB,localFrameA,localFrameB);
What we need to do is to use localFrame to find the previous Pivot:

Code: Select all

btTransform localA=spHingeDynAB->getAFrame();
btVector3 localAorigin=localA.getOrigin();
btVector3 pivotInA=localA*btVector3(btScalar(0),btScalar(0),btScalar(1))-localAorigin;
Hi, Dirk, could you please check if these equations are right ?

Cheers !