c# - 从矩阵变换计算角度

标签 c# wpf math matrix

我有以下代码行: 我在不知道值(多少度)的情况下对矩形应用了很少的旋转。现在我想获得二维元素的旋转或角度。

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/

相关文章:

c# - WPF TextBlock 绑定(bind)不起作用

wpf - ScrollBar 模板中的奇数行/列尺寸

algorithm - P 中的质数 - 运行到 sqrt 怎么样?

c++ - 多边形分割与三角剖分

c# - 在数据库中保存 "Select Multiple"值

c# - 如何在EF Core Code First中创建枚举对应的表?

c# - 定时器速度问题WPF

c# - 修改nHibernate在nServiceBus中保存Saga数据的方式

.net - WPF 中的 StackPanel 与 DataGrid 与 DockPanel

python - 如果找到零,python 乘法表达式的计算速度会更快吗?