Last active
          June 27, 2022 14:46 
        
      - 
      
- 
        Save angeldevil/7670877 to your computer and use it in GitHub Desktop. 
    Calculate the real scale and degree of rotation from an Android Matrix
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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)); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Thanks!