Reputation: 1403
I wrote a program (like this) that generate and apply a transformation matrix to an object thanks to user's input on scalings, skews, rotations and translations.
Now I want to do it inversely: given the transformation matrix, how to calculate the these values? The matrix is 2D (a, b, c, d, tx, ty).
I know this is a pure math problem but I was not concentrated enough in high school...
Upvotes: 1
Views: 4018
Reputation: 41484
Assuming a translate/rotate/scale&skew order of operations, the easiest thing to do is to snip them off one at a time.
Upvotes: 2
Reputation: 1403
I found a lot of useful info on this tutorial which solved the problem for me. Here is the formula for those who cares:
Translation (pixel)
x := tx
y := ty
Scale (time)
scale_x := sqrt(a^2 + b^2)
scale_y := sqrt(c^2 + d^2)
Skew (degree)
skew_x := 180/pi * atan2(d, c) - 90
skew_y := 180/pi * atan2(b, a)
Rotation (degree)
This is the tricky part: rotation is not a basic transform function; in fact it is the result of the combination of skew and scale. You can skew an object by its x
and y
axis and then scale it to make it look like it has been rotated. The angle of x skew is usually regarded as the rotation angle:
rotation := skew_x
Sometimes:
rotation := skew_y
Upvotes: 5