• FEATURED

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

Calculating the required rotation.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

#1Wilhelm van Huyssteen  Members

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).

#2Cornstalks  Members

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 ]

#3max343  Members

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.

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

#4Álvaro  Members

Posted 03 January 2013 - 07:49 PM

There is a notion of a "most natural" rotation that maps A to B. I found this link for you.

#5quasar3d  Members

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

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

#6Wilhelm van Huyssteen  Members

Posted 05 January 2013 - 08:10 AM

Thanks I got it working.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.