#### Archived

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

# Quaternion Interpolation

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

## Recommended Posts

Can somebody give me the basic of what quaternion and the interpolation process so that it can make a smooth path ?? Plzzz... I''m not very good at math so any basic things will do and will be appreciated very much

##### Share on other sites
sure here it comes
  void __forceinline QuatLerp( const qVect p, qVect q, float t, qVect qt ){ int i; float omega, cosom, sinom, sclp, sclq; // decide if one of the quaternions is backwards float a = 0; float b = 0; for (i = 0; i < 4; i++) { a += (p[i]-q[i])*(p[i]-q[i]); b += (p[i]+q[i])*(p[i]+q[i]); } if (a > b) { for (i = 0; i < 4; i++) { q[i] = -q[i]; } } cosom = p[0]*q[0] + p[1]*q[1] + p[2]*q[2] + p[3]*q[3]; // very small value if ((1.0 + cosom) > 0.00000001f) { if ((1.0 - cosom) > 0.00000001f) { omega = acos( cosom ); sinom = sin( omega ); sclp = sin( (1.0f - t)*omega) / sinom; sclq = sin( t*omega ) / sinom; } else { sclp = 1.0f - t; sclq = t; } for (i = 0; i < 4; i++) { qt[i] = sclp * p[i] + sclq * q[i]; } } else { qt[0] = -p[1]; qt[1] = p[0]; qt[2] = -p[3]; qt[3] = p[2]; sclp = sin( (1.0f - t) * 0.5f * __PI); sclq = sin( t * 0.5f * __PI); for ( i = 0 ; i < 3 ; i++ ) { qt[i] = sclp * p[i] + sclq * qt[i]; } }}

Edited by - Magmai Kai Holmlor on December 29, 2001 2:37:17 PM

##### Share on other sites
Sorry i''ve posted too quickly , perhaps, the qVect actually is
simple a float a[4] array , and __PI is the venerable PI this is easy , if you have something more to ask, just do it.

##### Share on other sites
well what are those parameters means anyway ??
what about the quartenion for the rotation ??

##### Share on other sites
  void __forceinline AngleQuaternion( fVect angles, qVect quaternion ){ float angle; float sr, sp, sy, cr, cp, cy; angle = angles[2] * 0.5f; sy = sin(angle); cy = cos(angle); angle = angles[1] * 0.5f; sp = sin(angle); cp = cos(angle); angle = angles[0] * 0.5f; sr = sin(angle); cr = cos(angle); quaternion[0] = sr*cp*cy-cr*sp*sy; // X quaternion[1] = cr*sp*cy+sr*cp*sy; // Y quaternion[2] = cr*cp*sy-sr*sp*cy; // Z quaternion[3] = cr*cp*cy+sr*sp*sy; // W}void __forceinline QuaternionMatrix( qVect quaternion, fMatrix matrix ){ matrix[0][0] = 1.0f - 2.0f * quaternion[1] * quaternion[1] - 2.0f * quaternion[2] * quaternion[2]; matrix[1][0] = 2.0f * quaternion[0] * quaternion[1] + 2.0f * quaternion[3] * quaternion[2]; matrix[2][0] = 2.0f * quaternion[0] * quaternion[2] - 2.0f * quaternion[3] * quaternion[1]; matrix[0][1] = 2.0f * quaternion[0] * quaternion[1] - 2.0f * quaternion[3] * quaternion[2]; matrix[1][1] = 1.0f - 2.0f * quaternion[0] * quaternion[0] - 2.0f * quaternion[2] * quaternion[2]; matrix[2][1] = 2.0f * quaternion[1] * quaternion[2] + 2.0f * quaternion[3] * quaternion[0]; matrix[0][2] = 2.0f * quaternion[0] * quaternion[2] + 2.0f * quaternion[3] * quaternion[1]; matrix[1][2] = 2.0f * quaternion[1] * quaternion[2] - 2.0f * quaternion[3] * quaternion[0]; matrix[2][2] = 1.0f - 2.0f * quaternion[0] * quaternion[0] - 2.0f * quaternion[1] * quaternion[1];}

....please don't make me expalin the theory behind quaternions
it is too long for a post....:-(((((
i hope this function will be usefull for you

Edited by - Magmai Kai Holmlor on December 29, 2001 2:39:16 PM

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633696
• Total Posts
3013402
×