No need to normalize this quaternion

Started by
10 comments, last by Dmytry 19 years, 7 months ago
My math lib will provide two separate classes to avoid such mistakes. xUQuat and xQuat. Thus every function of UQuat will ensure that the norm predicate is maintained (with switchable asserts to debug your code). In general there is no need for a sqrt, each operator will contain a custom and optimized renormalization code. To make it more efficient, one can use explicit casts and avoid much of the intermediate renormalizations. Well one still has to know what he computes.

Example (stupid physics like) code :

xUQuat myFunc(xUQuat &_A, xUQuat &_B)
{
xQuat &A=(xUQuat)_A;
xQuat &B=(xUQuat)_B;
// constructor normalizes automatically
xUQuat C(A*B + 2.0f*B + slerp(A,B, 0.3f));
return C;
}
"Coding math tricks in asm is more fun than Java"
Advertisement
Yes,summ of two quaternions *0.5 is not unit-length, unless
both quaternions is equal or very close to be equal.

Length of (A+B)*0.5 in fact is equal to cosine of half-angle between A and B. (where A and B may be quaternions or vectors of any dimension)

Quote:Original post by Charles B
My math lib will provide two separate classes to avoid such mistakes. xUQuat and xQuat. Thus every function of UQuat will ensure that the norm predicate is maintained (with switchable asserts to debug your code). In general there is no need for a sqrt, each operator will contain a custom and optimized renormalization code. To make it more efficient, one can use explicit casts and avoid much of the intermediate renormalizations. Well one still has to know what he computes.

Example (stupid physics like) code :

xUQuat myFunc(xUQuat &_A, xUQuat &_B)
{
xQuat &A=(xUQuat)_A;
xQuat &B=(xUQuat)_B;
// constructor normalizes automatically
xUQuat C(A*B + 2.0f*B + slerp(A,B, 0.3f));
return C;
}

that's good idea, maybe will add that thing to my math lib too - currently i renormalize too often. Doesn't matter for camera but may matter for some other things....if normalization takes about 200 computer cycles, that's 15M normalizations per second on 3GHz system...

This topic is closed to new replies.

Advertisement