This topic has not yet been rated - Rate this topic

Matrix.Shear Method (Single, Single)

Applies the specified shear vector to this Matrix by prepending the shear transformation.

Namespace:  System.Drawing.Drawing2D
Assembly:  System.Drawing (in System.Drawing.dll)
public void Shear(
	float shearX,
	float shearY
)

Parameters

shearX
Type: System.Single
The horizontal shear factor.
shearY
Type: System.Single
The vertical shear factor.

The transformation applied in this method is a pure shear only if one of the parameters is 0. Applied to a rectangle at the origin, when the shearY factor is 0, the transformation moves the bottom edge horizontally by shearX times the height of the rectangle. When the shearX factor is 0, it moves the right edge vertically by shearY times the width of the rectangle. Caution is in order when both parameters are nonzero, because the results are hard to predict. For example, if both factors are 1, the transformation is singular (hence noninvertible), squeezing the entire plane to a single line.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, an Paint event object. The code performs the following action:

  • Draws a rectangle to the screen, using a green pen, prior to applying a scaling transform.

  • Creates a Matrix and uses it to set a world-coordinate transform for the Graphics.

  • Draws another rectangle using a red pen.

  • Draws an ellipse using a blue pen.

The result is a green rectangle, a red parallelogram and a transformed, blue ellipse. Notice that the green rectangle (drawn prior to setting the transform) directly uses the coordinates supplied in the DrawRectangle call. The other two figures are transformed prior to drawing. The rectangle is transformed to a parallelogram (red), and the ellipse (blue) is transformed to fit into the transformed parallelogram. Notice the bottom of the rectangle is moved (sheared) in the x-axis by a factor of two times the height of the rectangle, thus forming the parallelogram.


public void MatrixShearExample(PaintEventArgs e)
{
    Matrix myMatrix = new Matrix();
    myMatrix.Shear(2, 0);
    e.Graphics.DrawRectangle(new Pen(Color.Green), 0, 0, 100, 50);
    e.Graphics.MultiplyTransform(myMatrix);
    e.Graphics.DrawRectangle(new Pen(Color.Red), 0, 0, 100, 50);
    e.Graphics.DrawEllipse(new Pen(Color.Blue), 0, 0, 100, 50);
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ