• Advertisement

Archived

This topic is now archived and is closed to further replies.

Integrate function and quaternions

This topic is 5270 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

Hello, i have already implemented my phisycs simulator but i was using matrix rotation..now i''m need to implement quaternion to represent my rotation..so...i don''t know how to update the quaternion in my integrate function. when i update the matrix rotation i use the following line: target.orientation= source.orientation+ (aux* source.orientation)*delta_time; what should i use here to update the quaternion with the angular_velocity........ Now i''m using the following code with matrix rotation: void Integrate() { target.position= source.position+ (source.velocity* delta_time); cMATRIX3_x_3 aux = cMATRIX3_x_3(source.angular_velocity); target.orientation= source.orientation+ (aux* source.orientation)*delta_time; target.quat.Matrix_To_Quat(target.orientation); target.velocity= source.velocity+ source.force* (delta_time * OneOverMass) ; target.angular_momentum source.angular_momentum + source.torke * delta_time; target.orientation.Ortho_Normalize (); cMATRIX3_x_3 transp; target.orientation.Transpose (transp); target.invw_inertia_tensor = target.orientation*invb_inertia_tensor * transp; target.angular_velocity = target.invw_inertia_tensor * target.angular_momentum; } So ..how can i change it to suport quaternions?

Share this post


Link to post
Share on other sites
Advertisement
this is what I use for converting angular velocity and angular position to quaternions


//-------------------------------------------------------

// Euler Integration

//-------------------------------------------------------

m_LinAcceleration = m_Forces * m_InvMass;
m_RotAcceleration = m_Torques * m_InvInertia;

m_Position += m_LinVelocity * m_dt + m_LinAcceleration * (m_dt*m_dt*0.5f);

//----------------------------------------------------------------------

// Poisot equation to integrate for orientation

//----------------------------------------------------------------------

Quaternion Qvel = Quaternion(m_RotVelocity, 0) * m_Q * 0.5f;
Quaternion Qaccel = Quaternion(m_RotAcceleration, 0) * m_Q * 0.5f;

m_Q += Qvel * m_dt + Qaccel * (m_dt*m_dt*0.5f); // standard euler equation, like for position


m_Q.Normalise();

//----------------------------------------------------------------------

// Convert quaternion to matrix

//----------------------------------------------------------------------

m_Orientation = m_Q;

//----------------------------------------------------------------------

// Calculate world cordinate inertia matrix

//----------------------------------------------------------------------

m_InvInertia = m_Orientation * m_InvBoxInertia * m_Orientation.Inverse();

//----------------------------------------------------------------------

// integrate for velocity

//----------------------------------------------------------------------

m_LinVelocity += m_LinAcceleration * m_dt;
m_RotVelocity += m_RotAcceleration * m_dt;

//-----------------------------------------------------------------------

// Reset forces

//-----------------------------------------------------------------------

m_LinAcceleration = Vector(0, 0, 0);
m_RotAcceleration = Vector(0, 0, 0);
m_Forces = Vector(0, 0, 0);
m_Torques = Vector(0, 0, 0);


Share this post


Link to post
Share on other sites
oh..thanks....for posting

Can you post the code to += quaternion operator overload? i think i''m doing it right but it doesn''t seen to work.. and...what kind of initialization you are doing in the code
Quaternion(m_RotVelocity, 0)
can you post it plz?

Share this post


Link to post
Share on other sites
But ! Remember that rotation formula is acceptable only if rotation speed is comparable slow to integration step.

Share this post


Link to post
Share on other sites

  • Advertisement