Matrix オブジェクトと matrix パラメータで指定した行列を、 order パラメータで指定した順序で乗算します。
Overloads Public Sub Multiply( _
ByVal matrix As Matrix, _ ByVal order As MatrixOrder _)
[C#]
public void Multiply(Matrixmatrix,MatrixOrderorder);
[C++]
public: void Multiply(Matrix* matrix,MatrixOrderorder);
[JScript]
public function Multiply(
matrix : Matrix,order : MatrixOrder);
パラメータ
- matrix
Matrix オブジェクトと乗算する Matrix オブジェクト。 - order
乗算の順序を表す MatrixOrder 列挙体。
解説
指定された順序が MatrixOrder.Prepend の場合、この Matrix オブジェクトは指定された行列の前に付加して乗算されます。指定された順序が MatrixOrder.Append の場合、この Matrix オブジェクトは指定された行列の後に追加して乗算されます。
使用例
[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 OnPaint イベントのオブジェクトである PaintEventArgs e が必要です。このコードは次のアクションを実行します。
- 3 つの行列を作成します。
- 画面に行列 1 の内容を一覧表示します。
- 行列 1 と行列 2 を乗算し、結果を行列 1 に格納します。
- 画面に行列 1 の内容を一覧表示します。
- 行列 1 に格納されている結果と行列 3 を乗算し、結果を再び行列 1 に格納します。
- 画面に行列 1 の内容を一覧表示します。
- 行列 1 の変換を適用する前に、画面に四角形を描画します (青い四角形)。
- 四角形に変換を適用します。
- 前の四角形と同じ座標を使用して、変形した四角形を画面に描画します (赤い四角形)。
[Visual Basic, C#] 赤い四角形は水平方向に 2 倍に拡大され、90 度回転されてから、x 方向に 250 ポイント、y 方向に 50 ポイント移動 (平行移動) されます。
Public Sub MultiplyExample(e As PaintEventArgs)
Dim myPen As New Pen(Color.Blue, 1)
Dim myPen2 As New Pen(Color.Red, 1)
' Set up the matrices.
Dim myMatrix1 As New Matrix(2F, 0F, 0F, 1F, 0F, 0F)
' Scale.
Dim myMatrix2 As New Matrix(0F, 1F, - 1F, 0F, 0F, 0F)
' Rotate 90.
Dim myMatrix3 As New Matrix(1F, 0F, 0F, 1F, 250F, 50F)
' Translate.
' Display the elements of the starting matrix.
ListMatrixElementsHelper(e, myMatrix1, "Beginning Matrix", 6, 40)
' Multiply Matrix1 by Matrix 2.
myMatrix1.Multiply(myMatrix2, MatrixOrder.Append)
' Display the result of the multiplication of Matrix1 and
' Matrix2.
ListMatrixElementsHelper(e, myMatrix1, _
"Matrix After 1st Multiplication", 6, 60)
' Multiply the result from the pervious multiplication by
' Matrix3.
myMatrix1.Multiply(myMatrix3, MatrixOrder.Append)
' Display the result of the previous multiplication
' multiplied by Matrix3.
ListMatrixElementsHelper(e, myMatrix1, _
"Matrix After 2nd Multiplication", 6, 80)
' Draw the rectangle prior to transformation.
e.Graphics.DrawRectangle(myPen, 0, 0, 100, 100)
e.Graphics.Transform = myMatrix1
' Draw the rectangle after transformation.
e.Graphics.DrawRectangle(myPen2, 0, 0, 100, 100)
End Sub
' A helper function to list the contents of a matrix.
Public Sub ListMatrixElementsHelper(e As PaintEventArgs, _
matrix As Matrix, matrixName As String, numElements As Integer, _
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
[C#]
public void MultiplyExample(PaintEventArgs e)
{
Pen myPen = new Pen(Color.Blue, 1);
Pen myPen2 = new Pen(Color.Red, 1);
// Set up the matrices.
Matrix myMatrix1 = new Matrix(
2.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f); // Scale
Matrix myMatrix2 = new Matrix(
0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f); // Rotate 90,
Matrix myMatrix3 = new Matrix(
1.0f, 0.0f, 0.0f, 1.0f, 250.0f, 50.0f); // Translate
// Display the elements of the starting matrix.
ListMatrixElements(e, myMatrix1, "Beginning Matrix", 6, 40);
// Multiply Matrix1 by Matrix 2.
myMatrix1.Multiply(myMatrix2, MatrixOrder.Append);
// Display the result of the multiplication of Matrix1 and
// Matrix2.
ListMatrixElements(e,
myMatrix1,
"Matrix After 1st Multiplication",
6,
60);
// Multiply the result from the pervious multiplication by
// Matrix3.
myMatrix1.Multiply(myMatrix3, MatrixOrder.Append);
// Display the result of the previous multiplication
// multiplied by Matrix3.
ListMatrixElements(e,
myMatrix1,
"Matrix After 2nd Multiplication",
6,
80);
// Draw the rectangle prior to transformation.
e.Graphics.DrawRectangle(myPen, 0, 0, 100, 100);
// Make the transformation.
e.Graphics.Transform = myMatrix1;
// Draw the rectangle after transformation.
e.Graphics.DrawRectangle(myPen2, 0, 0, 100, 100);
}
//-------------------------------------------------------
// The following function is a helper function to
// list the contents of a matrix.
//-------------------------------------------------------
public void ListMatrixElements(
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;
}
}
[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
Matrix クラス | Matrix メンバ | System.Drawing.Drawing2D 名前空間 | Matrix.Multiply オーバーロードの一覧