Matrix.Reset 메서드

정의

항등 매트릭스의 요소를 포함하도록 이 Matrix를 다시 설정합니다.

public:
 void Reset();
public void Reset ();
member this.Reset : unit -> unit
Public Sub Reset ()

예제

다음 코드 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 개체인 이 Paint 필요합니다PaintEventArgse. 코드는 다음 작업을 수행합니다.

  • 크기 조정 행렬을 만듭니다.

  • 행렬 요소를 화면에 Lists.

  • 행렬을 ID로 다시 설정합니다.

  • 요소를 화면에 Lists.

  • 행렬을 x축에서 50포인트, y축에서 40포인트로 변환합니다.

  • 변환된 행렬의 요소를 화면에 Lists.

  • 행렬 변환(파란색 사각형)을 적용하기 전에 화면에 사각형을 그립니다.

  • 사각형에 변환을 적용합니다.

  • 이전 사각형과 동일한 좌표를 사용하여 변환된 사각형을 화면(빨간색 사각형)에 그립니다.

빨간색 사각형은 크기가 조정되지 않았지만(다시 설정으로 인해) x축 및 y축으로 변환되었습니다.

public:
   void ResetExample( PaintEventArgs^ e )
   {
      Pen^ myPen = gcnew Pen( Color::Blue,1.0f );
      Pen^ myPen2 = gcnew Pen( Color::Red,1.0f );

      // Create a matrix that scales by 5 in the x direction and
      // by 3 in the y direction.
      Matrix^ myMatrix = gcnew Matrix( 5.0f,0.0f,0.0f,3.0f,0.0f,0.0f );

      // List the matrix elements to the screen.
      ListMatrixElements( e, myMatrix, "Beginning Matrix", 6, 20 );

      // Reset the matrix to identity.
      myMatrix->Reset();

      // Again list the matrix elements to the screen.
      ListMatrixElements2( e, myMatrix, "Matrix After Reset", 6, 40 );

      // Translate the matrix by 50 points in the x-axis and 40 points
      // in the y-axis.
      myMatrix->Translate( 50.0f, 40.0f );

      // List the matrix elements to the screen.
      ListMatrixElements1( e, myMatrix, "Matrix After Translation", 6, 60 );

      // Draw a rectangle to the screen.
      e->Graphics->DrawRectangle( myPen, 0, 0, 100, 100 );

      // Apply the matrix transform to the Graphics.
      e->Graphics->Transform = myMatrix;

      // Draw another rectangle to the screen that has the transform
      // applied.
      e->Graphics->DrawRectangle( myPen2, 0, 0, 100, 100 );
   }

   //-------------------------------------------------------
   // This function is a helper function to
   // list the contents of a matrix.
   //-------------------------------------------------------
   void ListMatrixElements2( PaintEventArgs^ e, Matrix^ matrix, String^ matrixName, int numElements, int y )
   {
      // Set up variables for drawing the array
      // of points to the screen.
      int i;
      float x = 20,X = 200;
      System::Drawing::Font^ myFont = gcnew System::Drawing::Font( "Arial",8 );
      SolidBrush^ myBrush = gcnew SolidBrush( Color::Black );

      // Draw the matrix name to the screen.
      e->Graphics->DrawString( String::Concat( matrixName, ":  " ), myFont, myBrush, (float)x, (float)y );

      // Draw the set of path points and types to the screen.
      for ( i = 0; i < numElements; i++ )
      {
         e->Graphics->DrawString( String::Concat( matrix->Elements[ i ], ", " ), myFont, myBrush, (float)X, (float)y );
         X += 30;
      }
   }
public void ResetExample(PaintEventArgs e)
{
    Pen myPen = new Pen(Color.Blue, 1);
    Pen myPen2 = new Pen(Color.Red, 1);
             
    // Create a matrix that scales by 5 in the x direction and
    // by 3 in the y direction.
    Matrix myMatrix = new Matrix(
        5.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f); 
             
    // List the matrix elements to the screen.
    ListMatrixElements(e, myMatrix, "Beginning Matrix", 6, 20);
             
    // Reset the matrix to identity.
    myMatrix.Reset();
             
    // Again list the matrix elements to the screen.
    ListMatrixElements2(e, myMatrix, "Matrix After Reset", 6, 40);
             
    // Translate the matrix by 50 points in the x-axis and 40 points
    // in the y-axis.
    myMatrix.Translate(50.0f, 40.0f); 
  
    // List the matrix elements to the screen.
    ListMatrixElements1(e, myMatrix, "Matrix After Translation", 6, 60);
             
    // Draw a rectangle to the screen.
    e.Graphics.DrawRectangle(myPen, 0, 0, 100, 100);
             
    // Apply the matrix transform to the Graphics.
    e.Graphics.Transform = myMatrix;
             
    // Draw another rectangle to the screen that has the transform
    // applied.
    e.Graphics.DrawRectangle(myPen2, 0, 0, 100, 100);
}
             
//-------------------------------------------------------
// This function is a helper function to
// list the contents of a matrix.
//-------------------------------------------------------
public void ListMatrixElements2(
    PaintEventArgs e,
    Matrix matrix,
    string matrixName,
    int numElements,
    int y)
{
             
    // Set up variables for drawing the array
    // of points to the screen.
    int i;
    float x = 20, X = 200;
    Font myFont = new Font("Arial", 8);
    SolidBrush myBrush = new SolidBrush(Color.Black);
             
    // Draw the matrix name to the screen.
    e.Graphics.DrawString(
        matrixName + ":  ",
        myFont,
        myBrush,
        x,
        y);
             
    // Draw the set of path points and types to the screen.
    for(i=0; i < numElements; i++)
    {
        e.Graphics.DrawString(
            matrix.Elements[i].ToString() + ", ",
            myFont,
            myBrush,
            X,
            y);
        X += 30;
    }
}
Public Sub ResetExample(ByVal e As PaintEventArgs)
    Dim myPen As New Pen(Color.Blue, 1)
    Dim myPen2 As New Pen(Color.Red, 1)
    Dim myMatrix As New Matrix(5.0F, 0.0F, 0.0F, 3.0F, 0.0F, 0.0F)

    ListMatrixElementsHelper2(e, myMatrix, "Beginning Matrix", 6, 20)
    myMatrix.Reset()
    ListMatrixElementsHelper(e, myMatrix, "Matrix After Reset", 6, 40)

    ' Translate.
    myMatrix.Translate(50.0F, 40.0F)

    ListMatrixElementsHelper(e, myMatrix, "Matrix After Translation", _
        6, 60)
    e.Graphics.DrawRectangle(myPen, 0, 0, 100, 100)
    e.Graphics.Transform = myMatrix
    e.Graphics.DrawRectangle(myPen2, 0, 0, 100, 100)
End Sub

' A helper function to list the contents of a matrix.
Public Sub ListMatrixElementsHelper2(ByVal e As PaintEventArgs, _
ByVal matrix As Matrix, ByVal matrixName As String, ByVal numElements As Integer, _
ByVal y As Integer)

    ' Set up variables for drawing the array
    ' of points to the screen.
    Dim i As Integer
    Dim x As Single = 20
    Dim j As Single = 200
    Dim myFont As New Font("Arial", 8)
    Dim myBrush As New SolidBrush(Color.Black)

    ' Draw the matrix name to the screen.
    e.Graphics.DrawString(matrixName + ":  ", myFont, myBrush, x, y)

    ' Draw the set of path points and types to the screen.
    For i = 0 To numElements - 1
        e.Graphics.DrawString(matrix.Elements(i).ToString() + ", ", _
        myFont, myBrush, j, y)
        j += 30
    Next i
End Sub

설명

ID 행렬의 기본 대각선에 있는 요소는 1입니다. ID 행렬의 다른 모든 요소는 0입니다.

적용 대상