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 PaintEventArgse, 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 = gcnew Matrix;
      myMatrix->Shear( 2, 0 );
      e->Graphics->DrawRectangle( gcnew Pen( Color::Green ), 0, 0, 100, 50 );
      e->Graphics->MultiplyTransform( myMatrix );
      e->Graphics->DrawRectangle( gcnew Pen( Color::Red ), 0, 0, 100, 50 );
      e->Graphics->DrawEllipse( gcnew Pen( Color::Blue ), 0, 0, 100, 50 );
   }

.NET Framework
Available since 1.1
Return to top
Show: