Version 2, last updated by wycc at September 29, 2010 01:46 UTC

Location of the group

In the SVG, it's impossible to get the location of an element even for simple shape, such as rectangle. The translation and matrix attribute can be defined in elements and their parents. We need to consider all of these matrixes when we calculate the location of the object.

In addition, for path elements, we can not get the location and size of the them from directly. In order to improve the precision, we modify the inkscape with the attached patches, which will generate the following attributes. * bbox-x * bbox-y * bbox-width * bbox-height * transformation-center-x * transformation-center-y

Originally, these are attributes that the inkscape use them in the editor to get the bounding box of an element. We can use them to decide the bounding box as well.

Coordinate transformation

However, please be warned that the number in these attributes is relative to the group. For example, if the bbox-x and bbox-y is (100,400), it does not mean that the object will be rendered at (100,400) of the screen. We need to consider the transformation matrix of the element and their parents. In order to get the physical location in the screen, we need to calculate the accumulated transformation matrix of the transformation matrix of the element and their parents and use this matrix to calculate the final destination.

If their is no transformation matrix in the element and all parents, we can use the m[2] as the x coordinate and m[5] as the y coordinate. However, most of times, the transformation matrix will not be zero. In this case, if we want to move the element to (x,y), we need to use the transformation matrix and the bbox-x and bbox-y to decide the m[2] and m[5].

x = m0*bx+m1*by+m2;
y = m3*bx+m4*by+m5;

We can solve the equation and get the m2 and m5 as

m2 =  x - m0*bx - m1*by;
m5 =  y - m3*bx - m4*by;