我有以下代码行: 我在不知道值(多少度)的情况下对矩形应用了很少的旋转。现在我想获得二维元素的旋转或角度。
Rectangle element = (Rectangle)sender;
MatrixTransform xform = element.RenderTransform as MatrixTransform;
Matrix matrix = xform.Matrix;
third.Content = (Math.Atan(matrix.M21 / matrix.M22)*(180/Math.PI)).ToString();
and the matrix is like following
|M11 M12 0|
|M21 M22 0|
|dx dy 1| which is Transformation Matrix I guess !!
这似乎不是正确的值。 我想获得 0 到 360 度
的角度最佳答案
供将来引用:
这将为您提供以弧度为单位的变换矩阵的旋转角度:
var radians = Math.Atan2(matrix.M21, matrix.M11);
如果需要,您可以将弧度转换为度数:
var degrees = radians * 180 / Math.PI;
关于c# - 从矩阵变换计算角度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14125771/