In svg we have method element.getCTM()
which returns a SVGMatrix
as:
[a c e][b d f][0 0 1]
I want to calculate sx , sy and angle of rotation from this matrix.
In svg we have method element.getCTM()
which returns a SVGMatrix
as:
[a c e][b d f][0 0 1]
I want to calculate sx , sy and angle of rotation from this matrix.
There is a lot to read and learn on this subject. I'll give a basic answer, but be aware, if you are trying to do a game or animations this is NOT the way to do it.
a == sx
andd == sy
, so you'll access these like this:Now for the rotation
a == cos(angle)
andb == sin(angle)
. Asin and acos can't alone give you the complete angle, but together they can. You want to use atan sincetan = sin/cos
and for just this kind of problem you actually want to useatan2
:If you study the inverse trigonometric functions and the unit circle you'll understand why this works.
Here is W3C's indespensible resource on SVG transformations: http://www.w3.org/TR/SVG/coords.html. Scroll down a bit and you can read a lot more about what I've mentioned above.
UPDATE, example usage how to programmatically do animations. Keep the transformations stored separately and when these are updated, overwrite/update the SVG element transform.