I suspect there is some way to use an element’s transformation matrix to calculate its coordinates after being transformed, but I don’t know how to do so.
An example diagram explains this best:
I’m afraid I didn’t take the math route into programming. I can sort-of follow the surface-level details of what a transformation matrix is doing, but my understanding is sort of like being able to read music one note at a time, and only very slowly; I don’t really understand the tune at a higher level, so I don’t really understand the sound of a complete musical phrase—let alone the melody.
Similarly, I don’t understand how transformation matrices work. I have tried searching for explanations to grok transformation matrices, but everything I find is loaded with more math jargon I don’t understand. I just know that they work sort of like a function, and that they are incredibly flexible tools, but that’s it.
Of all the methods available to SVGMatrix
(supposedly deprecated in favor of DOMMatrix
, but Firefox Dev. ed. is still using SVGMatrix
), I have no idea whether .inverse()
or .multiply()
is what I want, and no idea how to coax a simple set of x
and y
coordinates out of that matrix.
Note:
- I am not interested in translating screen-to-SVG coordinates here.
- I am only concerned with SVG (user-space) coordinates.
You can use simple trigonometric transformation:
The snippet displays rotation of a blue point around the red one (30 / 90 / 123 degrees counter-clockwise)