Reputation: 29153
I'm not sure if this is possible, but basically I have two degrees that will change the width/size and skew of an image. In a tranformation matrix (<Matrix3DProjection/>
), it works like this:
M11:cos(x) M12:sin(y)*sin(x) M11:0 M21:0 M22:cos(y) M23:0 M31:0 M32:0 M33:1
So if I have X = 30°
and Y=40°
, my matrix is:
M11:0.866 M12:0.321 M11:0 M21:0 M22:0.766 M23:0 M31:0 M32:0 M33:1
So becomes
What I'd like to use instead is a <TransformGroup/>
but can't quite figure out the <SkewTransform AngleY="???"/>
portion. The <ScaleTransform/>
seems easy enough by using M11 and M22 values above in ScaleX
and ScaleY
like <ScaleTransform ScaleX=".866" ScaleY=".766"/>
.
But I can't figure out the AngleY
portion of <SkewTransform/>
from an M12
value of 0.321. I know that from doinking around with this manually, a value of AngleY="20.3"
seems very accurate. But I can't figure out the math behind this.
Does anyone know?
Upvotes: 3
Views: 662
Reputation: 59139
You can use Reflector on the SkewTransform class to find out the math. It calls Matrix.Skew, which uses the matrix:
1.0 tan(skewY) 0.0
tax(skewX) 1.0 0.0
Since you want tan(skewY) * 0.766 = 0.321
, you get skewY = atan(0.321 / 0.766) = 22.7366108 degrees
. Or, going back to your original numbers, skewY = atan(sin(y) * sin(x) / cos(y)) = atan(tan(y) * sin(x))
, which yields atan(tan(40 degrees) * sin(30 degrees)) = 22.7604763 degrees
.
Upvotes: 3
Reputation: 189467
Trying to read between the lines a little you want to avoid using the Projection
property and use to the RenderTransform
instead?
If so rather than trying to work out how to use ScaleTransform
and SkewTransform
just use the MatrixTransform
in the RenderTransform
.
<MatrixTransform Matrix=".866, .321, 0, .766, 0, 0" />
OR
<MatrixTransform M11="0.866" M12="0.321", M22="0.766" />
Upvotes: 0