Re: retrieve shapes coordinates / remove transformations
- --- In firstname.lastname@example.org, "johan.brelet" <johan.brelet@...> wrote:
>You can call the element's method getCTM() to retrieve the current transformation matrix resulting from all transformations on it and its ancestor elements. To apply that transformation you would in some cases have to convert basic shapes to paths. (A scaled and translated rectangle or ellipse is still an ellipse, but if rotated you need a path.) If you want to keep basic shapes as basic shapes whenever possible, there will be a lot of case distinctions to be done. All basic shapes can be converted to equivalent paths.
> In fact I need to remove all transformations attributes (translate, rotate, ...) in SVG in order to retrieve shapes exact coordinates.
When it comes to transforming paths, I have implemented this in the function transformPath in my paths.js at
It uses some things defined in util.js, especially the function transformEllipse. Transforming ellipses (needed for ellipse, circle, and rect with rounded corners, as well as "a" commands in paths) with general matrizes is rather complicated. It requires calculating eigenvalues and eigenvectors. You probably won't want to figure the math out yourself, so use my code.