# Extracting overall angle from a matrix

Hi - was wondering if anyone could help with this problem.

If I have a square, which is like this:
Code:
A-----B
|     |
|     |
C-----D

and I then apply a transform matrix to it, which might consist of multiple rotations and translations, is there any way to determine what the overall angle is between the horizontal and the line AB of the square?

I am assuming there is a way to do this, because it is always possible to just draw out the square with the matrix applied to it, on paper and just measure the angle that it makes to the horizontal with a protractor. However I have no idea how to go about working out the angle purely mathematically.

The matrix I am using is of the form:
[a] [c] [e]
[d] [f]
[0] [0] [1]

I would appreciate any help with this.
Thanks

You're using an x-y coordinate frame. The angle that AB makes with respect to the x axis is just the inverse tangent of YAB/XAB, where YAB is the y component of A minus the y component of B.

Hi - thanks for the help.

I should say that this is for use with Javascript and SVG.

The problem is that I don't know what the x and y coordinates are of any of the corners once the matrix is applied to it. I know the x and y position of the top left hand corner of the square before the matrix is applied to it, however when you apply the matrix to it, according to the computer, the x and y coordinates of the square stay the same even though the position of the top left hand corner has moved.

So because I don't have the x and y coordinates of the corners A or B I can't use that formula.

Do you have any suggestions on how I could work out the position of A and B just by using the coordinates of the square before the matrix is applied, and the matrix itself?

Sorry if this post isn't very clear.

It looks like you're applying a rotation matrix to the components.

i.e.

r'=Mr
where M is your matrix and r is the triplet r=(rx,ry,rz). Is that correct?

erm - i'm not really sure what that means - my maths has never been very good.

Maybe this explains it better:
http://www.w3.org/TR/SVG/coords.html
if you search for: "Mathematically, all transformations can be represented as 3x3 transformation matrices of the following form:" without the speech marks that section explains how the matrix system I am using works.

OK.

Are you transforming the coordinate system (x and y axes) or are you transforming the box, whilst keeping the coordinate system fixed?

These are largely equivalent processes, but it would be nice to know which one you're doing.

Hi - sorry for the delay in replying. I was expecting to get an email but it never arrived.

When I apply the matrix, the coordinate system of the object is changed to reflect the matrix. So, for example if I rotate the object by 30 degrees, the coordinate system of the object, will rotate 30 degrees. However, the 'base' coordinate system stays the same. So in essence you have a coordinate system within another coordinate system.

If you have a look here: http://www.w3.org/TR/SVG/images/coords/RotateScale.svg  you will need Internet explorer with the Adobe SVG Viewer plugin or just firefox to view that file [/edit] the black lines along the top and left hand side is the 'base' coordinate system, and the red lines are the new coordinate system for each matrix.

So in answer to your question, i am transforming a 'child' coordinate system within a fixed coordinate system.