Skip to content

Instantly share code, notes, and snippets.

@angeldevil
Last active June 27, 2022 14:46
Show Gist options
  • Save angeldevil/7670877 to your computer and use it in GitHub Desktop.
Save angeldevil/7670877 to your computer and use it in GitHub Desktop.
Calculate the real scale and degree of rotation from an Android Matrix
float[] v = new float[9];
matrix.getValues(v);
// translation is simple
float tX = v[Matrix.MTRANS_X];
float tY = v[Matrix.MTRANS_Y];
// calculate real scale
float scaleX = values[Matrix.MSCALE_X];
float skewY = values[Matrix.MSKEW_Y];
float realScale = (float) Math.sqrt(scaleX * scaleX + skewY * skewY);
// calculate the degree of rotation
float skewX = v[Matrix.MSKEW_X];
float realAngle = Math.round(Math.atan2(skewX, scaleX) * (180 / Math.PI));
@shashluchok
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment