I need to get the x/y positions of an element that is written like this in SVG:
我需要得到在SVG中这样写的元素的x/y位置:
<g transform="scale(10,10)" id="g6558">
<text transform="matrix(1,0,0,-1,236.532,417.253)" id="text6560">
<tspan x="0 4.448" y="0" id="tspan6562">10</tspan>
</text>
</g>
How do I get the current position of the tspan
element in this case? I have to manually calculate them as I can't use getBBox()
or other native functions because I'm using a Flash-wrapper to display the SVG (http://code.google.com/p/svgweb/) which only supports basic attributes, tag names etc.
在这种情况下,如何获得tspan元素的当前位置?我必须手动计算它们,因为我不能使用getBBox()或其他本机函数,因为我使用了一个flash包装器来显示SVG (http://code.google.com/p/svgweb/),它只支持基本属性、标签名称等。
How are the matrices and transformations caluclated on the x/y position of the element?
矩阵和变换是如何在元素的x/y位置上进行的?
1 个解决方案
#1
6
As well as i understood your problem, you need to know the x and y co-ordinates of an element, after it is transformed.
正如我理解您的问题一样,您需要了解元素的x和y坐标,在它被转换之后。
Mathematically, all transformations can be represented as 3x3 transformation matrices of the following form:
在数学上,所有的变换都可以表示为以下形式的3x3变换矩阵:
a b e
c d f
0 0 1
Since only six values are used in the above 3x3 matrix, a transformation matrix is also expressed as a vector: [a b c d e f]
. a and d responsible for scaling in x and y respectively, whereas e and f gives you the translated axis in the x and y respectively. So In your code which is
由于在3x3矩阵中只使用了6个值,一个变换矩阵也表示为一个向量:[a b c d e f]。a和d分别负责x和y的缩放,而e和f分别给出了x和y的翻译轴。在你的代码中。
<text transform="matrix(1,0,0,-1,236.532,417.253)" id="text6560">
<tspan x="0 4.448" y="0" id="tspan6562">10</tspan>
</text>
Element text is translated 236.532 in the x-axis 417.253 in the y-axis. So tspan x point becomes 236.. + 4.4.. and y point 417.. + 0.
元素文本在y轴的x轴417253中被翻译为236.532。所以tspan x点变成236。+ 4.4 . .和y点417 . .+ 0。
#1
6
As well as i understood your problem, you need to know the x and y co-ordinates of an element, after it is transformed.
正如我理解您的问题一样,您需要了解元素的x和y坐标,在它被转换之后。
Mathematically, all transformations can be represented as 3x3 transformation matrices of the following form:
在数学上,所有的变换都可以表示为以下形式的3x3变换矩阵:
a b e
c d f
0 0 1
Since only six values are used in the above 3x3 matrix, a transformation matrix is also expressed as a vector: [a b c d e f]
. a and d responsible for scaling in x and y respectively, whereas e and f gives you the translated axis in the x and y respectively. So In your code which is
由于在3x3矩阵中只使用了6个值,一个变换矩阵也表示为一个向量:[a b c d e f]。a和d分别负责x和y的缩放,而e和f分别给出了x和y的翻译轴。在你的代码中。
<text transform="matrix(1,0,0,-1,236.532,417.253)" id="text6560">
<tspan x="0 4.448" y="0" id="tspan6562">10</tspan>
</text>
Element text is translated 236.532 in the x-axis 417.253 in the y-axis. So tspan x point becomes 236.. + 4.4.. and y point 417.. + 0.
元素文本在y轴的x轴417253中被翻译为236.532。所以tspan x点变成236。+ 4.4 . .和y点417 . .+ 0。