Angle of Rotation from a transform matrix

Discuss SVG code, accessible via the XML Editor.
artimusp
Posts: 7
Joined: Sun Jun 13, 2010 11:17 am

Angle of Rotation from a transform matrix

Is there a way to get the angle of rotation from a svg transform matrix?

for example:

rectangle =

x = 0
y = 0
width = 200
height = 200

then I rotate the rectangle by 45 degrees and get

matrix(0.70710678,-0.70710678,0.70710678,0.70710678,-41.421356,100)

is there a way I can extract the degree (in radians is fine) from the matrix. I'm hoping this is the final missing piece I need for what I'm working with.

<rect
style="fill:#b3b3b3;stroke:none"
id="rect3632"
width="200"
height="200"
x="0"
y="0"
transform="matrix(0.70710678,-0.70710678,0.70710678,0.70710678,-41.421356,100)" />

sas
Posts: 404
Joined: Sat Oct 06, 2007 5:42 am

Re: Angle of Rotation from a transform matrix

For an SVG matrix of the form matrix(a,-b,b,a,c,d), where a and b are not both zero, the rotation angle is atan2(b,a). If an SVG matrix represents a rotation, then it will necessarily be of this form.

artimusp
Posts: 7
Joined: Sun Jun 13, 2010 11:17 am

Re: Angle of Rotation from a transform matrix

Perfect. Thanks very much.