【问题标题】:Creating a Skew AngleY from a Skew Factor for a Rhomboid in XAML从 XAML 中的菱形的倾斜因子创建倾斜 AngleY
【发布时间】:2010-07-12 05:45:03
【问题描述】:

我不确定这是否可行,但基本上我有两个度数会改变图像的宽度/大小和倾斜度。在转换矩阵 (<Matrix3DProjection/>) 中,它的工作方式如下:

M11:cos(x) M12:sin(y)*sin(x) M11:0 M21:0 M22:cos(y) M23:0 M31:0 M32:0 M33:1

所以如果我有X = 30° 和Y=40°,我的矩阵是:

M11:0.866 M12:0.321 M11:0 M21:0 M22:0.766 M23:0 M31:0 M32:0 M33:1

所以 变成了

我想改用<TransformGroup/>,但不太清楚<SkewTransform AngleY="???"/> 部分。通过在ScaleX 和ScaleY 中使用上面的 M11 和 M22 值,<ScaleTransform/> 似乎很简单,例如 <ScaleTransform ScaleX=".866" ScaleY=".766"/>。

但我无法从 0.321 的M12 值中找出<SkewTransform/> 的AngleY 部分。我知道,通过手动操作,AngleY="20.3" 的值似乎非常准确。但我无法弄清楚这背后的数学原理。

有人知道吗?

【问题讨论】:

    标签: wpf silverlight math geometry skew


    【解决方案1】:

    您可以在 SkewTransform 类上使用 Reflector 来找出数学。它调用Matrix.Skew,使用矩阵:

    1.0           tan(skewY)    0.0
    tax(skewX)    1.0           0.0
    

    既然你想要tan(skewY) * 0.766 = 0.321,你就会得到skewY = atan(0.321 / 0.766) = 22.7366108 degrees。或者,回到你原来的数字,skewY = atan(sin(y) * sin(x) / cos(y)) = atan(tan(y) * sin(x)),得到atan(tan(40 degrees) * sin(30 degrees)) = 22.7604763 degrees。

    【讨论】:

    • 天哪,我对此寄予厚望。不幸的是,22.76 的值不能让 AngleY 显示与M12=0.321 相同的剪切。我也尝试过其他计算,但对他们也不起作用。它是否也与其他东西有关,比如我的矩形的宽度/高度?
    • @Otaku:啊,我在做 Skew 然后是 Scale,但是你在做 Scale 然后是 Skew。这应该只是颠倒我的公式中的 X 和 Y,产生atan(tan(30 degrees) * sin(40 degrees)) = 20.3605749 degrees。
    • 太棒了,就是这样!谢谢!
    【解决方案2】:

    想要避免使用Projection 属性并改用RenderTransform 来代替行间阅读?

    如果是这样,不要试图弄清楚如何使用ScaleTransform 和SkewTransform,只需在RenderTransform 中使用MatrixTransform。

     <MatrixTransform Matrix=".866, .321, 0, .766, 0, 0" />
    

    或

     <MatrixTransform M11="0.866" M12="0.321", M22="0.766" />
    

    【讨论】:

      猜你喜欢
      • 2020-03-06
      • 2019-12-15
      • 2015-03-21
      • 2020-04-12
      • 2016-12-25
      • 2016-12-23
      • 2018-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多