# Closest 3x3 rotation matrix where all entries are in {1, 0, -1}

Let $$M$$ be a 3x3 right-handed rotation matrix. I need to find a closed form solution for the right-handed rotation matrix $$M'$$ where its entries are lie in $${1, 0, -1}$$.

An initial idea is to replace each row of $$M$$ by the unit norm vector that is collinear to its largest component; i.e if the first row is $$[0.126, -0.946, -0.299]$$, then it should be replaced by $$[0, -1, 0]$$.

Any thoughts on this? Is there a better approach? What if one of the rotation angles is 45 degrees and the max component is not unique?

• There are only 24 possible answers, so a possibility is to brute force it. Undoubtedly there exists something more efficient, but do you care? Anyway, my initial thought is that something like $$\frac13\pmatrix{-1&2&2\cr2&-1&2\cr2&2&-1\cr}$$ could be the worst case from the point of view of breaking ties. – Jyrki Lahtonen Feb 27 at 22:07
• May be there is something quite efficient if we view the rotations in the quaternion space? Quantizing a quaternion to the closest "legal" alternative? Is there a useful description of the Voronoi cells? I need to think about this more. Past midnight here, and I really should hit the sack. – Jyrki Lahtonen Feb 27 at 22:13
• By 'closest' rotation a good definition I think needs not only to produce the closest vectors but also in the closest order. If we only consider cosine distance of vectors to one another, there will always be 3 subsolutions for each solution because we can rotate xyz to zxy to yzx and keep the same vectors with the same handedness – Roulbacha Feb 27 at 23:31

Looking at the original motivation I do not fully understand OP's own answer (what is an orthogonal rotation? For me any rotation is represented by an orthogonal matrix), but maybe this helps: say that the reference frame of the scanner is identified with the canonical basis $$\{e_i\}$$ of $$\mathbb{R}^3$$, that is $$e_1= (1,0,0), \ldots$$. Then, if I understand what the OP wrote, by the usual facts about the matrix associated to a linear map, the $$i$$-th column of your rotation matrix $$R$$ is the vector $$R(e_i)$$, that is the rotated basis vector (more precisely the column gives you the components of $$R(e_i)$$ with respect to the basis $$\{e_i\}$$).