Moderators: Sascha Willems, walaber
The quaternions Newton returns from a body also are completely different than the quaternions my code calculates, so there is no way to tell it the rotation I want.
dirMag = dirMag2 * dirMagInv;
omegaMag = dFloat(2.0f) * dAtan2 (dirMag, dq.m_q0) / dt;
omegaMag = dFloat(2.0f) * acos (dq.m_q0) / dt;
Method CalcAverageOmega:TVec3( QB:TQuat, dt:Double=1.0 )
Const REALLYSMALLNUMBER:Double=0.00001
Local dirMag:Double
Local dirMag2:Double
Local omegaMag:Double
Local dirMagInv:Double
Local dq:TQuat
Local omegaDir:TVec4
Local dq2:TQuat
dq=Inverse().Times(QB)
omegaDir=vec4(dq.x,dq.y,dq.z,dq.w)
dirMag2=omegaDir.dot(omegaDir);
If dirMag2<REALLYSMALLNUMBER*REALLYSMALLNUMBER Return vec3(0)
dirMagInv=1.0/Sqr(dirMag2)
omegaMag=2.0*ACos(dq.w)/dt
Return (omegaDir.xyz()).Scale(dirMagInv*omegaMag)
EndMethod
omegaMag=2.0*Asin(dq.w)/dt
omegaMag=2.0*Sgn(Asin(dq.w))/dt
I seem to have better luck with this:
- Code: Select all
omegaMag=2.0*Sgn(Asin(dq.w))/dt
Method CalcAverageOmega:TVec3( QB:TQuat, dt:Double=1.0 )
Const REALLYSMALLNUMBER:Double=0.00001
Local dirMag:Double
Local dirMag2:Double
Local omegaMag:Double
Local dirMagInv:Double
Local dq:TQuat
Local omegaDir:TVec4
Local dq2:TQuat
Local scale:Float
dq=Inverse().Times(QB)
omegaDir=vec4(dq.x,dq.y,dq.z,dq.w)
dirMag2=omegaDir.dot(omegaDir);
If dirMag2<REALLYSMALLNUMBER*REALLYSMALLNUMBER Return vec3(0)
dirMagInv=1.0/Sqr(dirMag2)
omegaMag=2.0*Sgn(ASin(dq.w))/dt
omegaDir.x:*-1.0
omegaDir.y:*-1.0
omegaDir.z:*-1.0
omegaDir.x=Degrees(omegaDir.x)
omegaDir.y=Degrees(omegaDir.y)
omegaDir.z=Degrees(omegaDir.z)
scale=Degrees(dirMagInv*omegaMag)
Return (omegaDir.xyz()).Scale(scale)
EndMethod
Users browsing this forum: No registered users and 20 guests