Assistance needed with NAN
May 17, 2009 at 7:32pm UTC
Hi all
Yet another question from me and hope some one shoots the answer immediately.. very simple though
I have been tryin to do a rigid body simulation ... things work fine until i hit a nan ..
What I am trying to do is retrieve a angle from a quaternion for which i wrote this following function...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
void get_AxisAngle_from_Quat(float &angle, Xlib::vec3d &axis)
{
float squareLength = get4d_X()*get4d_X() + get4d_Y()*get4d_Y() + get4d_Z()*get4d_Z();
if (squareLength>C_EPSILON)
{
angle = 2.0f * (float ) acos(get4d_Z());
//assert (!XlibMath::is__nan(angle));
float inverseLength ;
inverseLength = 1.0f / (float ) pow(squareLength, 0.5f) ;
axis.x = get4d_X() * inverseLength;
axis.y = get4d_Y() * inverseLength;
axis.z = get4d_Z() * inverseLength;
}
else
{
angle = 0.0f;
axis.x = 1.0f;
axis.y = 0.0f;
axis.z = 0.0f;
}
}
This is being refered in the code by this way
1 2 3 4 5 6 7
Xlib::vec3d axis(1,0,0);
float angle=0.0f;
RBody[0].q.get_AxisAngle_from_Quat(angle,axis);
Xlib::DevMsg("Quat " ,RBody[0].q);
Xlib::DevMsg("Angle " , angle);
but This hits a nan and everytime it hits nan my object disappears from the screen.... (DevMsg is a overload for cout i use) When i try printing out the values at the point where i hit the nan this shows this
1 2
DevMsg: Quat 1.442195 0.698514 1.700220 0.403262
Angle nan
I read online but it states nan is got by dividing by 0 .. but clearly i am not using any divisions at al...
can someone clarify me on where i went wrong ????
Cheers and regards
Last edited on May 17, 2009 at 7:33pm UTC
May 17, 2009 at 7:41pm UTC
I'm guessing it's here:
angle = 2.0f * (float ) acos(get4d_Z());
Make sure that get4d_Z() is returning values within the range of acos() (it's only defined from -1 to 1).
May 17, 2009 at 8:11pm UTC
bang on target........ thanks.. that was the problem ..
but now another problem is i do not know how to avoid it ;)))
Anyways thanks draco
Topic archived. No new replies allowed.