gpt4 book ai didi

android - 从android中的矩阵获取旋转值?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:49:39 24 4
gpt4 key购买 nike

如何从平移/缩放/旋转矩阵旋转值?

Matrix matrix = new Matrix();
matrix.postScale(...);
matrix.postTranslate(...);
matrix.postRotate(...);
...

现在我不知道 rotate 是什么,但我需要得到它。如何做到这一点?

最佳答案

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 = v[Matrix.MSCALE_X];
float skewy = v[Matrix.MSKEW_Y];
float rScale = (float) Math.sqrt(scalex * scalex + skewy * skewy);

// calculate the degree of rotation
float rAngle = Math.round(Math.atan2(v[Matrix.MSKEW_X], v[Matrix.MSCALE_X]) * (180 / Math.PI));

从这里开始 http://judepereira.com/blog/calculate-the-real-scale-factor-and-the-angle-of-rotation-from-an-android-matrix/

关于android - 从android中的矩阵获取旋转值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12256854/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com