Matrix.Reset Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Сбрасывает этот объект Matrix, чтобы получить элементы единичной матрицы.
public:
void Reset();
public void Reset ();
member this.Reset : unit -> unit
Public Sub Reset ()
Примеры
Следующий пример кода предназначен для использования с Windows Forms, и для него требуется PaintEventArgse
Paint объект события . Код выполняет следующие действия.
Создает матрицу масштабирования.
Списки элементы матрицы на экран.
Сбрасывает матрицу на удостоверение.
Списки элементы на экран.
Преобразует матрицу на 50 точек по оси X и 40 точек по оси Y.
Списки элементы преобразованной матрицы на экран.
Рисует прямоугольник, нарисованный на экране перед применением преобразования матрицы (синий прямоугольник).
Применяет преобразование к прямоугольнику.
Рисует преобразованный прямоугольник, нарисованный на экране (красный прямоугольник), используя те же координаты, что и предыдущий прямоугольник.
Обратите внимание, что красный прямоугольник не масштабировался (из-за сброса), а был преобразован на оси 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
Комментарии
Элементы в main диагонали матрицы идентификации — 1. Все остальные элементы матрицы идентификации имеют значение 0.
Применяется к
Обратная связь
https://aka.ms/ContentUserFeedback.
Ожидается в ближайшее время: в течение 2024 года мы постепенно откажемся от GitHub Issues как механизма обратной связи для контента и заменим его новой системой обратной связи. Дополнительные сведения см. в разделеОтправить и просмотреть отзыв по