Hi.

Given

(A) a constant 3D vector of (0,1, 0)

(B) any normalized 3D vector

How would I calculate the 3x3 rotation matrix that when used to transform (A) will result in (B).

Thanks in Advance!

Started by Jan 03 2013 06:30 PM

,
5 replies to this topic

Posted 03 January 2013 - 06:30 PM

Hi.

Given

(A) a constant 3D vector of (0,1, 0)

(B) any normalized 3D vector

How would I calculate the 3x3 rotation matrix that when used to transform (A) will result in (B).

Thanks in Advance!

Posted 03 January 2013 - 06:44 PM

Just a thought: Transform A and B into spherical coordinates, find their difference, and now you know the theta and phi rotations that must be applied to A to get B. Use theta and phi to create a 3x3 rotation matrix. There might be a better way, but that's what I'm thinking of off the top of my head.

Since A is fixed and known, you should be able to simplify it further.

**Edited by Cornstalks, 03 January 2013 - 06:45 PM.**

[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

Posted 03 January 2013 - 07:02 PM

This problem is ill-posed. The solution is not unique.

In case of (0,1,0) you can construct a special solution:

1. Choose two orthogonal vectors to B and to each other, call them B1 and B2.

2. Arrange these vectors into the columns of a matrix like this: R=[B2, B, B1], with B=B1 x B2.

The more general problem (any vector A) is easy as well, but still ill-posed.

In case of (0,1,0) you can construct a special solution:

1. Choose two orthogonal vectors to B and to each other, call them B1 and B2.

2. Arrange these vectors into the columns of a matrix like this: R=[B2, B, B1], with B=B1 x B2.

The more general problem (any vector A) is easy as well, but still ill-posed.

**Edited by max343, 03 January 2013 - 07:03 PM.**

Posted 04 January 2013 - 07:34 AM

There's indeed a most natural rotation. It's the one that leaves vectors perpendicular to the plane of A and B invariant.

To derive such a matrix, note that any composition of 2 (or any even number of) reflections is a rotation. With this, you can easily construct a matrix that satisfies your requirements.

Let S_1 be the matrix that reflects A to -A, and let S_2 be the matrix that reflects A + B to -(A + B). The composition S_2 S_1 is then your rotation matrix.

In vectors, reflecting a vector x in a normal vector n is

{eqn} x' = x - 2 n (n \cdot x) {/eqn}

or in matrix notation, where vectors are column vectors

{eqn}

x' = x - n (n^T x)

= (I - n n^T) x

{/eqn}

so your reflection matrix is then {eqn} I - n n^T {/eqn} so your rotation matrix, which rotates a to b

{eqn} R = (I - \frac{(a + b) (a + b)^T}{|a + b|^2)(I + \frac{a a^T}{|a|^2}) {/eqn}

EDIT: Can't get latex to work

To derive such a matrix, note that any composition of 2 (or any even number of) reflections is a rotation. With this, you can easily construct a matrix that satisfies your requirements.

Let S_1 be the matrix that reflects A to -A, and let S_2 be the matrix that reflects A + B to -(A + B). The composition S_2 S_1 is then your rotation matrix.

In vectors, reflecting a vector x in a normal vector n is

{eqn} x' = x - 2 n (n \cdot x) {/eqn}

or in matrix notation, where vectors are column vectors

{eqn}

x' = x - n (n^T x)

= (I - n n^T) x

{/eqn}

so your reflection matrix is then {eqn} I - n n^T {/eqn} so your rotation matrix, which rotates a to b

{eqn} R = (I - \frac{(a + b) (a + b)^T}{|a + b|^2)(I + \frac{a a^T}{|a|^2}) {/eqn}

EDIT: Can't get latex to work

**Edited by quasar3d, 04 January 2013 - 07:54 AM.**