How to get transformed / Rotated SVG path points

柔情痞子 提交于 2019-12-07 13:49:21

问题


I have rotated an SVG path element by setting the attribute transform="rotate(45)"

Now how could i get the rotated SVG path points ?

When i checked the attribute "d" its still showing the original points [ unrotated ].


回答1:


if you get point through path.getPointAtLength(), than you need to apply the transformation of the path to result. You get the total transform by:

var t = path.getTransformToElement( path.ownerSVGElement );
var abspoint = path.getPointAtLength( 0.5 ).matrixTransform( t );

I have not testes this,but this might be the way...

That is good for some points on the path. If the whole list of path data should be converted to absolute, than raphael might be the fastest solution...




回答2:


There's no functionality in svg itself that provides that. Not in jQuery either AFAIK.

The javascript library Raphaël contains a utility method for what you want though, see Raphael.transformPath.



来源:https://stackoverflow.com/questions/13508803/how-to-get-transformed-rotated-svg-path-points

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!