Solution to matrix creep.

Started by
12 comments, last by Richy2k 18 years, 5 months ago
Quote:The way jyk proposed above is good in efficiency, right you are, but it relies in that the z axis (or which ever) is correctly aligned, and alignes the other axes accordingly to this assumption.
You are absolutely right about that. If the angular displacement isn't too great this can be a reasonable approximation. (For example, I think the Doom 3 physics library uses this method for 3x3 matrix orthogonalization.) For the sake of simplicity I gave the example using a 'fixed forward' axis. In my own code however, the orthogonalization function is set up to perform n steps of iterative Gram-Schmidt first, where n is an argument and can be zero, and then finalizes with the cross-product method. For this latter step (which is the only step if n is zero), the caller can specify which of the three axis' direction is unchanged. For example, if the object is a spaceship you might choose to leave its forward direction unchanged by the orthogonalization.

As this thread shows, there are various ways to do it, and I may switch to something else in the future. But for now I like the above method as it gives the option of quick 'n dirty if you don't mind the approximation, or iterative if for some reason you need to converge on the solution.
Advertisement
An interesting method is Eric Raible's Matrix Orthogonalization from Graphics Gems I. His methods iterates and finds a new orthogonal ("orthonormal") matrix close to the original matrix.

Converting a distorted matrix to a quaternion and back to a matrix can also work OK (though for physics applications, it's best to use quaternions and convert once to matrix for point transformations).

An untried idea to prevent bias when using the cross-product (or Gram-Schmidt dot-projections) would be to interpolate the old matrix (basis vectors) to the new orthogonal matrix using weights based on axis order: the first axis would be used directly, the next axis would get a large weight, and the last axis would get a smaller weight (as it will have changed the most).
in my opinion, simply not using matricies for repeated computation is preferable. in my experience, most time spent in physics is not in matricies or integration, but in collision detection and response, so regenerating a couple matricies from euler angles (or quats) each frame is not an unbearable overhead, and saves you the successive numerical errors which inevitably creep into successive matrix concatenations.

james
It seems that using quaternions has given excellent results, little creep at all, even without normalising. Tried using orthogonalising the matrices....but that didn't do an aweful lot at all, just adds more overhead.
Adventures of a Pro & Hobby Games Programmer - http://neilo-gd.blogspot.com/Twitter - http://twitter.com/neilogd

This topic is closed to new replies.

Advertisement