*On 12/06/2013 at 03:04, ***xxxxxxxx** wrote:

BTW, this is slightly off-topic, but...

There is (or at least was - see below) a 'bug' in the supplied "MatrixToRotAxis()" routine. The axis + angle returned could _not_ be passed to the complimentary "RotAxisToMatrix()" routine to reproduce the original matrix.

I cobbled together this 'fix'...

```
//-----------------------------------------------------------------------------
// MyMatrixToRotAxis()
//-----------------------------------------------------------------------------
void MyMatrixToRotAxis(const Matrix &mm, Vector *v, Real *w)
{
Matrix m = mm;
// MatrixVectoren MUESSEN normiert sein!!!
m.v1=!m.v1;
m.v2=!m.v2;
m.v3=!m.v3;
// Winkel berechnen
*w = ACos((m.v1.x+m.v2.y+m.v3.z-1.0)/2.0);
// NOTE: subtraction order reversed (original Maxon code did not produce a
// axis \+ angle that could be used to reproduce the starting Matrix
// using RotAxisToMatrix())
// v->x= m.v2.z-m.v3.y;
// v->y= m.v3.x-m.v1.z;
// v->z= m.v1.y-m.v2.x;
v->x= m.v3.y-m.v2.z;
v->y= m.v1.z-m.v3.x;
v->z= m.v2.x-m.v1.y;
*v = !(*v);
if (*v==0.0)
{
*v = Vector(0.0,1.0,0.0);
*w = 0.0;
}
}
```

...now, I see that the code for "RotAxisToMatrix()" has since changed, so/but I have not yet validated what it returns - it may make my 'fix' above obsolete/invalid - I'm personally still calling the older version of that routine from an earlier SDK (included below for completeness) :

```
//-----------------------------------------------------------------------------
// MyRotAxisToMatrix()
//-----------------------------------------------------------------------------
Matrix MyRotAxisToMatrix(const Vector &v, Real w)
{
Matrix m;
if ((Abs(v.x)+Abs(v.y)+Abs(v.z))!=0.0 )
{
// zuerst mal den Vector normieren ...
m.v2 = !v;
// jetzt ein rechtes KS basteln
m.v1 = m.v2%Vector(0.0,0.0,1.0);
#ifdef _R12_SDK_
if (Len(m.v1)>MIN_EPSILON)
#else
if (Len(m.v1)>MINSIZE)
#endif
{
m.v3 = m.v1%m.v2;
}
else
{
m.v3 = Vector(1.0,0.0,0.0)%m.v2;
m.v1 = m.v2%m.v3;
}
// Rotationsmatrix im Pleft- und Rechtssystem um Y ist gleich
m = (m*MatrixRotY(w)) * !m;
}
return m;
}
```

...the latest version of the SDK code may now work correctly (? the only new comment just says that it's a "faster version", so the resulting values may be the same as before), but if not, then the above two routines should allow you to start with a matrix, extract an axis + angle using MyMatrixToRotAngle() and then feed those back into MyRotAxisToMatrix() to reproduce the original matrix. This fixed a major export -> import headache for me, many, many moons ago :).