I need to parse SVG (just the simples things) and only thing left to do is to properly extract position and angle from the matrix transformation. I know this question has been asked many times and I believe I have went through many of the answers, documents etc. but still cannot handle it proporly. Here's the simplest example I managed to prepare:
I have created 1000x1000 document (all numbers in px) and put a rectangle of 100x100 size at 100,100 position. It has generated the following piece of SVG file (I have removed style attrib. and parent tags). There's no other transformation anywhere in the file:
Code: Select all
<rect
width="100"
height="100"
x="100"
y="100" />
Then I have rotated the rectangle by 33deg (with the 'transform' inkscape tool). The SVG code looks this:
Code: Select all
<rect
width="100"
height="100"
x="-5.8952699"
y="157.49644"
transform="matrix(0.83867057,-0.54463904,0.54463904,0.83867057,0,0)" />
Now, my goal is to extract the position and angle from the matrix, so basically I'd like to get back the following values: x:100,y:100,angle:33. In order to do it, I have assumed the following formulas:
sx=sqrt(a^2+b^2)
sy=sqrt(c^2+d^2)
t=atan(c/d) OR t=atan(-b/a)
t=acos(a) if MATRIX is PURE
x' = tx + sx*(COS(t)*x-SIN(t)*y)
y' = ty + sy*(SIN(t)*x+COS(t)*y)
the result is:
t = 0.575958787 (which is 33deg) - PERFECTLY FINE
however
x'=-90.72230563 and y'=128.8770646
and this is exactly what totally confuses me - why it's not 100,100 ?
Please help, I have went through tons of forums, SVG W3C documentation and still cannot make it right.
Thank you,
Veedoo