<Grid> <StackPanel Orientation="Horizontal"> <StackPanel Width="300"> <TextBlock Margin="10,10,5,5" Text="Original Matrix:"/> <TextBlock x:Name="tbOriginal" Margin="20,0,5,5"/> <TextBlock Margin="10,0,5,5" Text="Inverted Matrix:"/> <TextBlock x:Name="tbInvert" Margin="20,0,5,5"/> <TextBlock Margin="10,0,5,5" Text="Original Matrices:"/> <TextBlock x:Name="tbM1M2" Margin="20,0,5,5"/> <TextBlock Margin="10,0,5,5" Text="M1 x M2:"/> <TextBlock x:Name="tbM12" Margin="20,0,5,5"/> <TextBlock Margin="10,0,5,5" Text="M2 x M1:"/> <TextBlock x:Name="tbM21" Margin="20,0,5,5"/> </StackPanel> <StackPanel Width="320"> <TextBlock Margin="10,10,5,5" Text="Original Matrix:"/> <TextBlock Name="tbOriginal1" Margin="20,0,5,5"/> <TextBlock Margin="10,0,5,5" Text="Scale:"/> <TextBlock Name="tbScale" Margin="20,0,5,5"/> <TextBlock Margin="10,0,5,5" Text="Scale - Prepend:"/> <TextBlock Name="tbScalePrepend" Margin="20,0,5,5"/> <TextBlock Margin="10,0,5,5" Text="Translation:"/> <TextBlock Name="tbTranslate" Margin="20,0,5,5"/> <TextBlock Margin="10,0,5,5" Text="Translation – Prepend:"/> <TextBlock Name="tbTranslatePrepend" Margin="20,0,5,5"/> <TextBlock Margin="10,0,5,5" Text="Rotation:"/> <TextBlock Name="tbRotate" Margin="20,0,5,5" TextWrapping="Wrap"/> <TextBlock Margin="10,0,5,5" Text="Rotation – Prepend:"/> <TextBlock Name="tbRotatePrepend" Margin="20,0,5,5" TextWrapping="Wrap"/> <TextBlock Margin="10,0,5,5" Text="RotationAt:"/> <TextBlock x:Name="tbRotateAt" Margin="20,0,5,5" TextWrapping="Wrap"/> <TextBlock Margin="10,0,5,5" Text="RotationAt – Prepend:"/> <TextBlock x:Name="tbRotateAtPrepend" Margin="20,0,5,5" TextWrapping="Wrap"/> <TextBlock Margin="10,0,5,5" Text="Skew:"/> <TextBlock Name="tbSkew" Margin="20,0,5,5"/> <TextBlock Margin="10,0,5,5" Text="Skew - Prepend:"/> <TextBlock Name="tbSkewPrepend" Margin="20,0,5,5"/> </StackPanel> </StackPanel> </Grid>
// Invert matrix: Matrix matrix = new Matrix(1, 2, 3, 4, 0, 0); tbOriginal.Text = "(" + matrix.ToString() + ")"; matrix.Invert(); tbInvert.Text = "(" + matrix.ToString() + ")"; // Matrix multiplication: Matrix m1 = new Matrix(1, 2, 3, 4, 0, 1); Matrix m2 = new Matrix(0, 1, 2, 1, 0, 1); Matrix m12 = Matrix.Multiply(m1, m2); Matrix m21 = Matrix.Multiply(m2, m1); tbM1M2.Text = "M1 = (" + m1.ToString() + "), " +" M2 = (" + m2.ToString() + ")"; tbM12.Text = "(" + m12.ToString() + ")"; tbM21.Text = "(" + m21.ToString() + ")"; //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // Original matrix: Matrix m = new Matrix(1, 2, 3, 4, 0, 1); tbOriginal1.Text = "(" + m.ToString() + ")"; //Scale: m.Scale(1, 0.5); tbScale.Text = "(" + m.ToString() + ")"; // Scale - Prepend: m = new Matrix(1, 2, 3, 4, 0, 1); m.ScalePrepend(1, 0.5); tbScalePrepend.Text = "(" + m.ToString() + ")"; //Translation: m = new Matrix(1, 2, 3, 4, 0, 1); m.Translate(1, 0.5); tbTranslate.Text = "(" + m.ToString() + ")"; // Translation - Prepend: m = new Matrix(1, 2, 3, 4, 0, 1); m.TranslatePrepend(1, 0.5); tbTranslatePrepend.Text ="(" + m.ToString() + ")"; //Rotation: m = new Matrix(1, 2, 3, 4, 0, 1); m.Rotate(45); tbRotate.Text = "(" + MatrixRound(m).ToString()+ ")"; // Rotation - Prepend: m = new Matrix(1, 2, 3, 4, 0, 1); m.RotatePrepend(45); tbRotatePrepend.Text = "(" +MatrixRound(m).ToString() + ")"; //Rotation at (x = 1, y = 2): m = new Matrix(1, 2, 3, 4, 0, 1); m.RotateAt(45, 1, 2); tbRotateAt.Text = "(" +MatrixRound(m).ToString() + ")"; // Rotation at (x = 1, y = 2) - Prepend: m = new Matrix(1, 2, 3, 4, 0, 1); m.RotateAtPrepend(45, 1, 2); tbRotateAtPrepend.Text = "(" +MatrixRound(m).ToString() + ")"; // Skew: m = new Matrix(1, 2, 3, 4, 0, 1); m.Skew(45, 30); tbSkew.Text = "(" + MatrixRound(m).ToString() + ")"; // Skew - Prepend: m = new Matrix(1, 2, 3, 4, 0, 1); m.SkewPrepend(45, 30); tbSkewPrepend.Text ="(" + MatrixRound(m).ToString() + ")"; private Matrix MatrixRound(Matrix m) { m.M11 = Math.Round(m.M11, 3); m.M12 = Math.Round(m.M12, 3); m.M21 = Math.Round(m.M21, 3); m.M22 = Math.Round(m.M22, 3); m.OffsetX = Math.Round(m.OffsetX, 3); m.OffsetY = Math.Round(m.OffsetY, 3); return m; }
reference : Practical WPF Graphics Programming
'.NET > WPF 2D' 카테고리의 다른 글
WPF 2D TranslateTransform (0) | 2013.07.03 |
---|---|
WPF 2D Scale Transforms (0) | 2013.06.28 |
WPF 2D Object Matrix Transforms (0) | 2013.06.28 |
WPF 2D Creating Perpendicular Lines (0) | 2013.06.27 |
WPF Basic 2D Graphics Shapes (0) | 2013.06.19 |
WPF 2D 차트에 대한 사용자 정의 좌표 (0) | 2013.06.18 |
WPF 2D RenderTransform ScaleTransform Slider 바인딩 Canvas.ClipToBounds (0) | 2013.06.18 |
WPF 2D 그리기 Canvas, Line, Canvas.RenderTransform, ScaleTransform, TranslateTransform (0) | 2013.06.18 |