views:

51

answers:

2

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 normal becomes 30x40

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?

A: 

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" />
AnthonyWJones
+3  A: 

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.

Quartermeister
Oh man, I had a lot of high hopes for this. Unfortunately, a value of 22.76 doesn't work for AngleY to show the same shear as `M12=0.321`. I've tried on other calculations as well and it doesn't work for them either. Could it also be related to something else, like the width/height of my rectangle?
Otaku
@Otaku: Ah, I was doing the Skew followed by the Scale, but you were doing the Scale followed by the Skew. That should just reverse X and Y in my formula, yielding `atan(tan(30 degrees) * sin(40 degrees)) = 20.3605749 degrees`.
Quartermeister
Brilliant, that's exactly it! Thank you!
Otaku