2012-07-18 85 views
0

可能重复:
How to get the actual x/y position of an element in SVG with transformations and matrices我们如何从转换矩阵得到x和y?

我需要的是在SVG这样写的一个元素的X/Y位置:

<image 
    y="-421.28461" 
    x="335.27295" 
    id="image2991" 
    xlink:href="file:///C:/Users/tom/Documents/t.jpg" 
    height="369" 
    width="360" 
    transform="matrix(0.22297057,0.97482518,-0.97482518,0.22297057,0,0)" /> 

这里x & y属性给出,但这不给图像的实际位置。虽然我知道在

变换矩阵[a,b,c,d,e,f]e & f分别给出了在x和y平移轴线。但

问题是,这里两个(e & f)都是0.现在我可以得到这个图像的实际x任何y

+0

它写满了。 'x =“335.27295”'''y =“ - 421.28461”' – Shai 2012-07-18 06:49:23

+0

但这不是元素 – 2012-07-18 06:50:30

+0

的实际x和y请参见[image element](http://www.w3.org/TR/SVG/struct .html#ImageElementXAttribute)来自SVG文档 – Shai 2012-07-18 06:51:13

回答

4

假设,

x="335.27295" 
y="-421.28461" 

鉴于变换矩阵

a    b   e 
c    d   f 
0    0   1 

具有值

0.22297057  0.97482518 0 
-0.97482518 0.22297057 0 
0    0   1 

知道

  • 一,d负责缩放X,Y respectivly
  • E,F是负责将X,Y respectivly

您`ll最终得到

newX = x * a + e 
newY = y * d + f 

或者,

newX = 335.27295 * 0.22297057 + 0 = 74.75 
newY = -421.28461 * 0.22297057 + 0 = -93.93 
+0

很多很多谢谢@Shai – 2012-07-18 07:23:47

+0

不应该变换矩阵是[[ace] [bdf] [0 0 1]]'(即,b和c相比于你的),按照http://www.w3.org/TR/SVG/coords.html#TransformMatrixDefined? – Robert 2015-12-14 03:07:17