# Thread: Finding a rotation matrix

1. ## Finding a rotation matrix

This is from our computer graphics class:

We have a unit sphere centered at the origin

We are given a rotation matrix R and a perspective projection matrix P
Let p be a unit vector that lies on the sphere.
then

c=P*R*p

and so c is the screen coordinate of p after being rotated by R and then projected using P.

Now for the question:
We are now provided with a different c which we shall call c1 and told that P and p remain the same. The question is what rotation matrix R1 will take p to c1?

Obviously this will produce an underconstrained system so the constraints are defined to be that R is composed of two axis rotations Rx(phi) (rotation of phi about x) and Rz(theta) (rotation of theta about z) such that

R=Rz(theta)*Rx(phi)

So the question boils down to
solve c1=P*Rz(theta)*Rx(phi)*p for theta and phi

You may assume that inv(P) exists or that we know the value of inv(P)*c1

2. The question could be made equivalent to this:

Given two points on a sphere p1 and p2 find theta and phi such that

Rx(phi)*Rz(theta)*p1=p2

where Rx(phi) is a rotation about x axis by phidegrees and Rz(theta) is a rotation about z axis by theta degrees

3. Generally, projection transformation from 3D to Plane is NOT invertible.
R is a span of matrices

4. Originally Posted by math2009
Generally, projection transformation from 3D to Plane is NOT invertible.
R is a span of matrices
Actually thats not entirely true. In computer graphics projection matrices are designed to be invertible and this is possible because they are usually 4x4 homogeneous transformations.

In any case I specified
You may assume that inv(P) exists or that we know the value of inv(P)*c1

given two points on a sphere p1 and p2
find the two rotations Rx and Rz such that
p2=Rx * Rz * p1

5. Hi
I have one method which works fine but was hoping someone would give me a purer method.

My method is to simply let v=p2-p1

then convert v into polar coordinates and extract theta and phi from those equations

Id really like to know how I can find Rx and Rz as the solutions to a set of constraints

6. I have one method which works fine but was hoping someone would give me a purer method.
Do you mean "simpler" method?

convert v into polar coordinates
Do you mean spherical coordinates? I'm not sure your method will work, because, while v would represent the difference of the two vectors, v is a straight-line way of getting from p1 to p2, whereas you are doing rotations to get there.

You may not be able to find just an Rx and Rz to rotate p1 to p2. You may also need an Ry.