
Briefly, to get the x,y position of a point after it's transformed, use a function like this (in Python):
def transform_point(transform, x, y): x = transform[0][0]*x + transform[0][1]*y + transform[0][2] y = transform[1][0]*x + transform[1][1]*y + transform[1][2] return x,y
If you need to modify the x,y position, it gets slightly more complicated, but only a little. 1) transform the point as above, to get the original values if you need them for anything 2) calculate the new values you need. 3) Transform them back to the original x,y space by using the matrix inverse: http://en.wikipedia.org/wiki/Matrix_inverse
In pseudo-code:
orig_x, orig_y = however_you_got_the_values_in_the_first_place() t_x, t_y = transform_point(transform, orig_x, orig_y) new_x_t, new_y_t = calculate_some_new_values(t_x, t_y) new_x, new_y = transform_point(invert_transform(transform), new_x_t,
new_y_t)
To get the matrix inverse isn't 100% straightforward, mathematically. It's easy in python, though. Here's the function I use (pretty much just a wrapper around numpy.matrix.I):
import numpy def invert_transform(transform): transform = transform[:] # duplicate list to avoid modifying it transform += [[0, 0, 1]] inverse = numpy.matrix(transform).I.tolist() inverse.pop() return inverse
- Bryan
On Mon, Jan 10, 2011 at 09:26, Bric <bric@...2538...> wrote:
On January 9, 2011 at 2:21 PM Bryan Hoyt | Brush Technology < bryan@...2310...> wrote:
Hi Bric,
Yes, you're correct. The x/y values are being translated, scaled,
rotated,
and/or sheared by the transform matrix. These pages on Wikipedia should
help
you to get started:
http://en.wikipedia.org/wiki/Transformation_(geometry)
Yes, I am using the (cos, sin, -sin, cos) rotation matrix in my script, and inkscape seems to visualize my rotation angle the way i intend. But, as is the issue, not the x/y position of my intent.
OK. Thanks for this info. At this point I can only vaguely understand how (and why) inkscape would store transformed values in the SVG file, instead of storing the original coordinates and then subjecting those to whatever transformation the applies, during render time. I'll have to get back to this later.
Also, it's not just the transform matrix on the object itself that you
need
to think about. If the text object is part of a group or a layer, then if there's a transform matrix on any of its parent groups or layers, they'll affect the object cumulatively.
thanks.
I've written Python code to handle all these scenarios in the Pixelsnap
extension. Have a look at the code for that if you want.
I skimmed through your code, and see that you are computing offsets based on transformation. Still, it looks complex for me right now; will have to return to it later when I have more time.
I can't wrap my mind around how exactly to apply the transformation to the x y position. I'll tinker with this later.
thanks again