I have following details with me :
<g transform="translate(20, 50) scale(1, 1) rotate(-30 10 25)">
Need to change above line to:
<g transform="matrix(?,?,?,?,?,?)">
Can anyone help me to achieve this?
I have following details with me :
<g transform="translate(20, 50) scale(1, 1) rotate(-30 10 25)">
Need to change above line to:
<g transform="matrix(?,?,?,?,?,?)">
Can anyone help me to achieve this?
Translate(tx, ty) can be written as the matrix:
Scale(sx, sy) can be written as the matrix:
Rotate(a) can be written as a matrix:
Rotate(a, cx, cy) is the combination of a translation by (-cx, cy), a rotation of a degrees and a translation back to (cx, cy), which gives:
If you just multiply this with the translation matrix you get:
Which corresponds to the SVG transform matrix:
(cos(a), sin(a), -sin(a), cos(a), -cx × cos(a) + cy × sin(a) + cx + tx, -cx × sin(a) - cy × cos(a) + cy + ty)
.In your case that is:
matrix(0.866, -0.5 0.5 0.866 8.84 58.35)
.If you include the scale (sx, sy) transform, the matrix is:
(sx × cos(a), sy × sin(a), -sx × sin(a), sy × cos(a), (-cx × cos(a) + cy × sin(a) + cx) × sx + tx, (-cx × sin(a) - cy × cos(a) + cy) × sy + ty)
Note that this assumes you are doing the transformations in the order you wrote them.
First get the g element using document.getElementById if it has an id attribute or some other appropriate method, then call consolidate e.g.
Maybe helpful:
Live demo of how to find actual coordinates of transformed points
An implementation of the accepted answer: