Matrix.Reset 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
重設這個 Matrix 使其具有身分識別矩陣的元素。
public:
void Reset();
public void Reset ();
member this.Reset : unit -> unit
Public Sub Reset ()
範例
下列程式代碼範例是設計來搭配 Windows Forms 使用,而且需要 PaintEventArgse
事件Paint物件。 此程式碼會執行下列動作:
建立縮放矩陣。
清單 矩陣元素到畫面。
將矩陣重設為身分識別。
清單 畫面中的元素。
將矩陣轉譯為 X 軸中的 50 點,而 Y 軸中為 40 點。
清單 轉譯矩陣的元素到畫面。
在套用矩陣轉換 (藍色矩形) 之前,繪製矩形到螢幕。
將轉換套用至矩形。
使用與上一個矩形相同的座標,繪製轉換后的矩形 (紅色矩形) 。
請注意,因為重設) ,但已轉譯為 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
備註
識別矩陣主要對角線上的元素為1。 識別矩陣的所有其他元素都是0。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應