Lets say we have a global coord system and local coord system and that local coord system is rotated by some amount by some arbitrary vector.

How could I find this rotation vector and angle given the two coord systems ?

**0**

# How to find a rotation of another coord system ?

###
#2
Crossbones+ - Reputation: **16257**

Posted 15 October 2013 - 07:23 AM

The amount of rotation does not depend on the coordinate system. The vector around which you are rotating should be expressed in the basis of the appropriate coordinate system. You normally convert between coordinate systems by a matrix multiplication, but I am not entirely sure what format you have your coordinate systems in.

###
#3
Members - Reputation: **294**

Posted 15 October 2013 - 10:22 AM

Matrix solution would be ok, but I was looking for a quaternion solution.

Ill try to give an eg. Lets say we have a normal coord system, and a vector defined in it as v(-0.5, 0, -1). And that there is another coord system (of an object) located at (2, 1, 1) and it is rotated by facing directly on opposite z, that is its x and y are the same as original coord system but its z is pointing in (0, 0, -1) in respect to original coord system.

What I want to know what are the coords of vector v in respect to the second coord system.

###
#4
Crossbones+ - Reputation: **16257**

Posted 15 October 2013 - 11:09 AM

The location of the origin of the coordinate systems is irrelevant for this particular problem, because we are converting only vectors. When you say "and it is rotated by facing directly on opposite z", you have to realize that that transformation is not a rotation at all: It's a reflection. The coordinates of v in the second coordinate system are (-0.5, 0, 1). If v is the axis of a rotation, you'll actually have to negate the rotation amount because the coordinate systems have different orientation.

**Edited by Álvaro, 15 October 2013 - 11:10 AM.**

###
#5
Members - Reputation: **294**

Posted 15 October 2013 - 12:16 PM

Hmm, Im all confused.

So you say the coords of vector v remain unchanged. I don't understand this.

Lets then say that a second coord system is not a reflection but a rotation with its forward vector (z component) its facing (0.5, 0, -1), and its up (y) and right (x) are orthonormalized in respect to forward (z), that is they are the same as in first coord system. What would than be the coord of a vector v ?

Would it still remain the same ?

I don't mean the rotation around vector v, just its coords in respect to second coord system.

**Edited by ryt, 15 October 2013 - 12:22 PM.**

###
#6
Crossbones+ - Reputation: **16257**

Posted 15 October 2013 - 01:01 PM

No, that's not what I say. The sign of z changed.So you say the coords of vector v remain unchanged.

I don't understand that description of a coordinate system. Just tell me what vector is (1,0,0) in the new coordinates, what vector is (0,1,0) and what vector is (0,0,1). From that we can build a 3x3 matrix and do all the operations easily.Lets then say that a second coord system is not a reflection but a rotation with its forward vector (z component) its facing (0.5, 0, -1), and its up (y) and right (x) are orthonormalized in respect to forward (z), that is they are the same as in first coord system.

###
#7
Members - Reputation: **294**

Posted 15 October 2013 - 01:25 PM

No, that's not what I say. The sign of z changed.So you say the coords of vector v remain unchanged.

I don't understand that description of a coordinate system. Just tell me what vector is (1,0,0) in the new coordinates, what vector is (0,1,0) and what vector is (0,0,1). From that we can build a 3x3 matrix and do all the operations easily.Lets then say that a second coord system is not a reflection but a rotation with its forward vector (z component) its facing (0.5, 0, -1), and its up (y) and right (x) are orthonormalized in respect to forward (z), that is they are the same as in first coord system.

Oh ok. To a response on your first quote.

I didnt notice that sign change, things are starting to be a little more clear now. So my question now is how did you do that ? Is there some matrix, quaternion inversion or maybe something else ?

On a second quote.

I meant for second coord system to be some object in space with its forward (z), up (y) and right (x) as a coord system. So for this object in its local coord system its basis are forward (0, 0, 1), up (0, 1, 0), right (1, 0, 0). But in terms of first coord system (the one where this object is placed) its basis are forward (0.5, 0, -1), up (0, 1, 0), right (1, 0, 0).

This time in second quote the object is not translated, its located at origin (for easier rapresentation). Note that its up and right are unchanged from first coord system, also for easier rapresentation.

So the thing I was actualy looking for is the vector v in terms of this object, that is its local coord system.

###
#8
Crossbones+ - Reputation: **5640**

Posted 15 October 2013 - 01:58 PM

You can just write down the matrix if you know what it does to (1, 0, 0), (0, 1, 0) and (0, 0, 1), it is just the images of those vectors after the transform as the rows of the matrix.

So to map (1, 0, 0) to (1, 0, 0); (0, 1, 0) to (0, 1, 0) and (0, 0, 1) to (0.5, 0, -1) you would use the matrix

(1, 0, 0)

(0, 1, 0)

(0.5, 0, -1)

and to map back you use the inverse of that matrix.

The matrix has determinant -1 (see http://www.wolframalpha.com/input/?i=det{{1%2C+0%2C+0}%2C+{0%2C+1%2C+0}%2C+{0.5%2C+0%2C+-1}} ), so it corresponds to a reflection and the orientation is flipped. You can't represent that transform with a unit quaternion since unit quaternions correspond to rotations and they all have determinant +1.

**Edited by Paradigm Shifter, 17 October 2013 - 02:02 PM.**

###
#10
Crossbones+ - Reputation: **5640**

Posted 15 October 2013 - 04:46 PM

Yeah I was gonna mention that at the end but deleted it.

You can make an orthonormal basis from independent ones using cross products and normalisation or use the Gram-Schmidt process http://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process

Unit quaternion rotations always give an orthonormal matrix (ignoring floating point inaccuracy) but you can't represent a reflection unless you also use a scale matrix to scale with a negative determinant.

###
#11
Members - Reputation: **1832**

Posted 16 October 2013 - 10:34 AM

The terms "local coordinate sytem" and "global coordinate system" are misnomers. In reality, there is only one coordinate system (that is used in computer graphics, anyway): the carthesian coordinate system. The "local" and "global" terms are usually used only to differentiate between coordinates before a certain transformation is applied to them (the "local coordinates") and the same, but already transformed coordinates (the "global coordinates"). From my experience, these terms are very rarely used in technical documentation, and when they are, they are used informally.

The transformation of one set of coordinates (a position vector) to another is done using a transformation matrix. The amount of rotation applied is held in this matrix, along with translation and scaling amounts. So if you have this matrix, you can get the rotation/translation and scaling amounts from it, using a function like D3DXMatrixDecompose.

**Edited by tonemgub, 16 October 2013 - 10:38 AM.**

###
#12
Members - Reputation: **294**

Posted 16 October 2013 - 10:56 AM

Yea, its my mistake, sorry. I was faster at typing than thinking. I thought they were orthogonal but obviously they cant be if two of them are (1, 0, 0), (0, 1, 0) and the third is rotated.

Here it is again complete, right (0.5, 0, -1), up (0, 1, 0), forward (1, 0, 0.5). Here they are orthogonal but if we normalize they become right (0.44, 0, -0.89), up (0, 1, 0), forward (0.89, 0, 0.44). Now they are also orthonormal.

The way Paradigm Shifter suggested it we could make a matrix from them like:

(044, 0, -0.89)

(0, 1, 0)

(0.89, 0, 0.44)

And the vector v is (-0.5, 0, -1). So I multiplied this matrix (lets call it M) with v and I got v' (0.67, 0, -0.88).

Now I wonder, are this the coords of a same point in space but in respect to the space of M ?

I really am not sure, always when I wanted to rotate some vector I would do it this way. So I think that this vector v' is a rotated vector and not the same vector in space.

**Edited by ryt, 16 October 2013 - 10:58 AM.**

###
#13
Crossbones+ - Reputation: **5640**

Posted 16 October 2013 - 12:01 PM

You need your right vector as the first row, and your forward as the 3rd. I think you have them swapped around.

To repeat, the first row of the matrix is what (1, 0, 0) is mapped to (so the right vector), 2nd row is what happens to (0, 1, 0) (your up), 3rd row is what happens to (0, 0, 1) (your forward).

###
#15
Crossbones+ - Reputation: **5640**

Posted 16 October 2013 - 12:19 PM

Ok. Do you want to transform in the other direction then? Use the inverse of M to do that. If the matrix is orthonormal, the inverse is the transpose.

###
#16
Members - Reputation: **294**

Posted 16 October 2013 - 12:59 PM

I don't know really, all I want is to now find the vector v' cords.

Actually v == v', they are the same point in space. v is defined as (-0.5, 0, -1), but I want its coords in therms of matrix M.

Imagine it like this, at the beginning we are located at origin of our coord system, we look around and we see another object (also at origin) with its local coord system as M. Its rotated a little bit counter clockwise (right hand system). And then you also see a point in space located at v (-0.5, 0, -1).

Now you transfer to the object coord system, and suddenly the matrix M that you saw before becomes:

(1, 0, 0)

(0, 1, 0)

(0, 0, 1)

And also everything else changes (coords of all objects) because we now look at everything from another coord system. But all objects and points haven't moved. They are at the same place as before. Now you take a look a point v and you see it at same position as before, that's why v == v'.

So now I want to know the coords of point v', that is from the point of view of our object (that rotated a little bit).

**Edited by ryt, 16 October 2013 - 01:01 PM.**

###
#17
Crossbones+ - Reputation: **5640**

Posted 16 October 2013 - 01:04 PM

I don't understand what you mean.

If you have v' = Mv

then

M^{-1}v' = v (multiply both sides on the left by M^{-1})

and if M is orthonormal then M^{-1 }= M^{T}

###
#18
Members - Reputation: **294**

Posted 16 October 2013 - 01:34 PM

I want to know the coord of vector v (-0.5, 0, -1) from the object (M) point of view.

I haven't sad that v' = Mv. I sad that I just multiplied it like that to get some point (to se what Ill get). But that's wrong because that's rotated point, and point v doesn't rotate and move. No point in space or object moves or rotates.

I simply transfer my point at "looking" at the world. The matrix M becomes my original point of view. Because of this every coordinate changes, even of point v.

The original coord system, the one where everything was defined, also changes and its right, up, forward coords when looked from new object (M).

Point v has not changed its position in terms where its located it space physically, just its coords change because we look at it from another point (M).

**Edited by ryt, 16 October 2013 - 01:38 PM.**

###
#19
Crossbones+ - Reputation: **5640**

Posted 16 October 2013 - 02:36 PM

I still don't understand what you are after. Applying a matrix to a vector changes the vector, and world space isn't special.

I think you are trying to do one of the following:

a) find v = M * (-0.5, 0, -1)^{T} (note, I use transpose there since the vector should be a column vector). That is easy, it's just a matrix * vector multiply.

or b) find vector p such that

(-0.5, 0, -1)^{T} = M * p

Then p = M^{-1} * (-0.5, 0, -1)^{T}

###
#20
Crossbones+ - Reputation: **16257**

Posted 16 October 2013 - 03:52 PM

I want to know the coord of vector v (-0.5, 0, -1) from the object (M) point of view.

I haven't sad that v' = Mv. I sad that I just multiplied it like that to get some point (to se what Ill get). But that's wrong because that's rotated point, and point v doesn't rotate and move. No point in space or object moves or rotates.

I like that you have this intuition that the point is a point and different coordinates are just different ways to describe the same unmoving object. Well, v is actually a vector, not a point, but the central idea is the same.

The thing is, when you convert coordinates in one basis to coordinates in another basis, the arithmetic involved is the same as in a transformation of the space. One way to think about it is that whether you move the camera or you move the world around it, the relative positions of the camera and the world are the same. Hopefully that clears up some of the miscommunication.

Now, let's use `v_A' to denote the coordinates of v in basis A and `v_B' to denote the coordinates of v in basis B. You can convert between v_A and v_B by matrix multiplication:

M * v_A = v_B

M is the matrix whose columns are the coordinates in B of the vectors that form basis A. The matrix that maps v_B to v_A is the inverse of M.

If you are dealing with orthonormal bases, the matrices involved are all rotations or reflected rotations, and the inverse is just the transpose, which is much easier to compute.