Transform matrix

Discuss SVG code, accessible via the XML Editor.
steg90
Posts: 3
Joined: Sun Jun 06, 2010 7:36 am

Transform matrix

Postby steg90 » Sun Jun 06, 2010 7:41 am

Hi,

Very new to this forum so please forgive me if I type any text in wrong!

I was wondering how I the tag : transform matrix is used. I have a rotated rectangle in Inkscape and it adds the transform matrix tag, how are the
6 values of it used? If I got an xpos of say 200 and ypos of 300, how can I use the contents of this matrix to transform it, i.e. rotate it? :tool_rectangle:
Do I just multiply the x and y position with the matrix (a b c d e f) ? I'm presuming e and f are the translated x and y positions and a b c d are the
rotations?

Many thanks,
Steve

steg90
Posts: 3
Joined: Sun Jun 06, 2010 7:36 am

Re: Transform matrix

Postby steg90 » Mon Jun 07, 2010 7:04 am

I'm convinced there is something wrong with the x and y coordinates in inkscape when you apply a rotation - they seem to be all over the place, either that or I am completely being stupid?!

When I have a rectangle and I apply a rotation of say 45 degs, it does the usual transform matrix, but the x and y attributes when looking at the xml just don't seem to be inline with that on the screen, what is wrong?!?!?!?!? Is it doing rotation then translation or something, sometimes I get negative xpositions when the ruler guide is showing the rectangle x position should be at a positive value...is this a bug???

I'm so confused with this now.

User avatar
tomh
Posts: 218
Joined: Sat Feb 14, 2009 10:14 pm

Re: Transform matrix

Postby tomh » Mon Jun 07, 2010 8:33 am

The best reference to how to use the transform matrix is probably the w3c specification: http://www.w3.org/TR/SVG/coords.html#Tr ... rixDefined

You can also use a rotate(), scale(), translate() and skewX() inside the transform attribute which is easier to understand for humans. See here: http://apike.ca/prog_svg_transform.html

Inkscape creates the matrix method because it's more general so the same code can cope with all the options, but can also process the other types.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Transform matrix

Postby ~suv » Mon Jun 07, 2010 9:10 am

steg90 wrote:but the x and y attributes when looking at the xml just don't seem to be inline with that on the screen, what is wrong?
I can't comment on the matrix questions and why e.g. when rotating a rectangle (an Inkscape shape, not a path) the base point (x,y) is translated as well as a matrix applied. But one thing that confused me early on - there are two coordinate systems in play:
  • Inkscape GUI: origin lower left corner of the page, y-axis pointing up, units: default document units
  • SVG source: origin upper left corner of the page, y-axis pointing down, units: px

steg90
Posts: 3
Joined: Sun Jun 06, 2010 7:36 am

Re: Transform matrix

Postby steg90 » Mon Jun 07, 2010 6:42 pm

Hi,

Looks like Inkscape is rotating and then translating? I just want to rotate a rectangle and have it to be at its original x,y position, not to have some very silly x,y value that don't seem to match with the gui grid in inkscape.

Tomh - how do you put the rotate into the transform attribute, everytime I apply a rotation, the xml shows transform matrix(.....)?!

Regards,
Steve

User avatar
tomh
Posts: 218
Joined: Sat Feb 14, 2009 10:14 pm

Re: Transform matrix

Postby tomh » Wed Jun 09, 2010 9:06 am

Looks like Inkscape is rotating and then translating? I just want to rotate a rectangle and have it to be at its original x,y position, not to have some very silly x,y value that don't seem to match with the gui grid in inkscape.


Inkscape has a concept of a rotation centre so when rotation is done from within Inkscape, it will happen about this:
see http://en.flossmanuals.net/Inkscape/SelectorTool under "Rotating" and "Rotation centre" headings

If you are hand editing the XML, then things get a bit more tricky, as the rotation is done about the co-ordinate system origin (In svg normally top left page border), although this can get transformed again to be the "user co-ordinate system": I don't understand this though! You would have to manually specify the correct displacement to the centre of the object you want to rotate.


Tomh - how do you put the rotate into the transform attribute, everytime I apply a rotation, the xml shows transform matrix(.....)?!

Yes, this is a bug in Inkscape. Inkscape knows how to do the rotate()->matrix() conversion, and uses this to display the rotation, however in the process it forgets the original rotate(). See: https://bugs.launchpad.net/inkscape/+bug/179309 It's an old bug...

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

Re: Transform matrix

Postby artimusp » Sun Jun 13, 2010 11:26 am

So like previously said. is there a way to get the exact x,y coordinates of a rectangle when it's been rotated. a non-rotated rectangle works fine but the moment it rotates the x and y get screwed up. I'm trying to use inkscape as a level editor which it seems to be perfect for. I'm basically just using it to export collision data for box2D physics engine which I have it all working as long as the rectangle doesn't get rotated. I really need to know how to get consistent coordinates. Or at least understand what's happening to the x and y after rotation so I can get the right values into my program.

Any help at all is much appreciated.

thanks,

Artimus


Return to “SVG / XML Code”