简体   繁体   English

SVG旋转变换矩阵

[英]SVG rotate transform Matrix

I parsed a transform attribute from an element in an SVG file something like rotate(45,30,50) and I would like to transform it to matrix form. 我从SVG文件中的一个元素解析了一个转换属性,比如rotate(45,30,50) ,我想把它转换成矩阵形式。 I searched for it and all I could found is only for rotate(a) with no coordinates which looks like this [cos(a) sin(a) -sin(a) cos(a) 0 0] 我搜索了它,所有我能找到的只是rotate(a)没有看起来像这样的坐标[cos(a) sin(a) -sin(a) cos(a) 0 0]

can any one show me how to transform the rotate(angle, x , y) to matrix form? 任何人都可以告诉我如何将rotate(angle, x , y)为矩阵形式?

Rotation matrices can only describe rotations about (0, 0), so you'll have to use a translation. 旋转矩阵只能描述关于(0,0)的旋转,因此您必须使用平移。

EDIT See this JSFiddle . 编辑看到这个JSFiddle It draws a rectangle defined with an offset, width and height, rotated around a pivot point. 它绘制一个矩形,定义为偏移,宽度和高度,绕枢轴点旋转。 The interesting part are the last 10 lines or so, where the value for offsetX and offsetY are computed. 有趣的部分是最后10行左右,其中计算了offsetXoffsetY的值。 Once you have these, you can build your translation and your rotation matrices. 获得这些后,您可以构建翻译和旋转矩阵。 Then, just multiply the translation by the rotation, and you'll get your final result. 然后,只需通过旋转乘以平移,您就可以得到最终结果。 Unfortunately, Javascript doesn't offer any matrix functionality, so if you don't provide your code this is all I can do 不幸的是,Javascript不提供任何矩阵功能,所以如果你不提供你的代码,这就是我所能做的

HOW A TRANSLATION MATRIX IS MADE 如何制作翻译矩阵

1   0   offsetX
0   1   offsetY
0   0      1

HOW A ROTATION MATRIX IS MADE 如何制作旋转矩阵

cos   -sin    0
sin    cos    0
 0      0     1

预习

I found an easier way to get the transformation matrix of an SVG element. 我找到了一种更简单的方法来获得SVG元素的变换矩阵。 Using the SVG element getCTM() method I can get the transformation matrix of the element, including rotation, translation and everything else. 使用SVG元素getCTM()方法我可以得到元素的变换矩阵,包括旋转,平移和其他所有东西。

To get svg transform matrix from a rotation with pivot point, 要从具有轴心点的旋转获得svg变换矩阵,

check this question answer 检查这个问题的答案

how to calculate svg transform matrix from rotation with pivot point 如何用旋转点从旋转计算svg变换矩阵

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM