Code: Select all
SIMD_FORCE_INLINE btQuaternion
shortestArcQuat(const btVector3& v0, const btVector3& v1)
{
btVector3 c = v0.cross(v1);
btScalar d = v0.dot(v1);
if (d < -1.0 + SIMD_EPSILON)
{
btVector3 n,unused;
btPlaneSpace1(v0,n,unused);
return btQuaternion(n.x(),n.y(),n.z(),0.0f); // just pick any vector that is orthogonal to v0
}
btScalar s = btSqrt((1.0f + d) * 2.0f);
btScalar rs = 1.0f / s;
return btQuaternion(c.getX()*rs,c.getY()*rs,c.getZ()*rs,s * 0.5f);
}
from s = btSqrt((1.0f + d) * 2.0f), I know s =2*cos(theta/2);
so I think rs should be sin(theta/2), rs = sqrt(1-pow(s/2,2)), and last return value should
be like [x*sin(theta/2),y*sin(theta/2),z*sin(theta/2),cos(theta/2)].
but why rs = 1.0f/s ;?
andbody can give me an explaination? thank you all!