Advertisement

QUATERNION EXPERTS - Can I ask you a question

Started by June 19, 2003 12:42 PM
3 comments, last by robert_s 21 years, 8 months ago
Hi. I''ve read some stuff on quaternions but I''ve never actually implemented anything in it. I just know some theory. Now, I am going to simulate a suspension system in my racing car. I would like to use quaternions for this purpose but I am not sure exactly which parts of my suspension should be simulated using quaternions. I am writing this app in DirectX and normally I would use matrices all over the place as this is whats available in DirectX but now if I want to use quaternions then which part of the whole suspension system should I use quaternions for. I guess anywhere I use an integrator (RK4) but how about wheels. Does it make sense to use them for wheels too? Thank you for help in advance!
quaternions for what? all the quaternions do is replace rotational matrices. If you want to use them, use them wherever you use matrices for rotation and orientation. I think you might be a bit confused about quaternions. The main advantages of quats is that they take less memory, can be interpolated, keep their composure much better than matrices, don''t suffer from Gimbal lock (?), they can be converted to matrices, and matrice can be converted to quaternions, quaternion operations are simpler. They are nice little things, although a bit abstract.

For your suspension, I''d guess, you could use them to compute the orientation of your suspension using the two end points.

void CalculateOrientation(const Vector &OriginalDirection, const Vector &NewDirection){	float	CosTheta = OriginalDirection * NewDirection;	float   CosTd2Sq = (CosTheta + 1.0f) * 0.5f;	float   CosTd2   = SquareRoot(CosTd2Sq);	float   SinTd2   = SquareRoot(1.0f - CosTd2Sq);        Vector RotAxis = OriginalDirection.Cross(NewDirection);	RotAxis.Normalise();	this->r = CosTd2;	this->V = RotAxis * SinTd2;}

Everything is better with Metal.

Advertisement
To "oliii"
take a look at nice implementation:
http://sourceforge.net/forum/forum.php?forum_id=122133

cheers.

inline void Quaternion::Rotation(const Vector& from, const Vector& to) {     Vector c = from.Cross(to);     float  d = from.Dot(to);         if (fabs(d) > 0.9999999f)     {         V.Zero();         r = Sign(d);         return;    }    df = from.GetLengthSquared();    dt =   to.GetLengthSquared();    MyAssert(df > 0.000000001f && dt > 0.0000000001f, "Vectors are bollocked. foo!");    this->V  = C;    this->r  = d + SquareRoot(df* dt);       Normalise();} 


does that seems fair?

[edited by - oliii on June 20, 2003 6:42:35 PM]

Everything is better with Metal.

to "oliii"
Almost perfect ! but

if (fabs(d) > 0.9999999f)
{
V.Zero();
r = Sign(d);
return;
}
not rotate in case of 180 degrees .

Can do so:
if ( d < 0.9999999f )
{
r = 0;
if( ( from.z*from.z ) > ( from.x*from.x ) ) V = from.Cross(Vector(1,0,0));
else V = from.Cross(Vector(0,0,1));
Normalise();
return;
}
just take a SOME rotation axe perpendicular to "from" and ratate by that.


This topic is closed to new replies.

Advertisement