Should I leave small values in my rotation matrix? [closed]
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this questionMy matrix
6.12303176911189E-17 1 0
-1 6.12303176911189E-17 0
0 0 1
Rotation matrix calculated here
0 1 0
-1 0 0
0 0 1
Question
Should I leave my matrix as it is, or should I set the small values to zero?
The function I use to generate rotation matrices
public void SetRotate(Vector axis, double angle)
{
double angleSin = Math.Sin(angle);
double angleCos = Math.Cos(angle);
double a = 1.0 - angleCos;
double ax = a * axis.X;
double ay = a * axis.Y;
double az = a * axis.Z;
_m11 = ax * axis.X + angleCos;
_m12 = ax * axis.Y + axis.Z * angleSin;
_m13 = ax * axis.Z - axis.Y * angleSin;
_m21 = ay * axis.X - axis.Z * angleSin;
_m22 = ay * axis.Y + angleCos;
_m23 = ay * axis.Z + axis.X * angleSin;
_m31 = az * axis.X + axis.Y * angleSin;
_m32 = az * axis.Y - axis.X * angleSin;
_m33 = az * axis.Z + angleCos;
}
Leave it, just because you can verify that the matrix computed for 90 degrees is different ever so slightly from the ideal result doesn't justify fixing the function for this single case.
If you add a fix for this you might as well add fixes for all other possible values as well...
The short answer is, leave it as is.
In your case, you are generating a general rotation matrix using floating point math, which is not exact: note that, even if your angle (in radians) is as close to pi/2 as possible, it will not be precisely 90 degrees.
If your goal is to clean things up before printing out numbers for human consumption, you should fix up the output. Setting small values to zero in the working matrix is almost certain to be actively wrong, and will come back to bite you when you least expect it...
It all depends, if that does not causes you any drawbacks (Z-Fighting between aligned planes, less readable code) and you need smooth transitions then leave it. Otherwise you might want to make rotations/scaling round to next degree/0.1 step.
精彩评论