You move, scale, rotate and mirror an object using a 4 by 4 transformation matrix represented by a Matrix3d object and the TransformBy method. You can also use the GetTransformedCopy method to create a copy of an entity and then apply the transformation to the copy. The Matrix3d object is part of the Geometry namespace.
利用 4 x 4 转换矩阵表示的一个 Matrix3d 对象和 TransformBy 方法,可以移动、缩放、旋转和镜像对象。也可以使用 GetTransformedCopy 方法创建一个图元的副本然后应用变换到副本中。Matrix3d 对象是 Geometry 命名空间的一部分。
The first three columns of the matrix specify scale and rotation. The fourth column of the matrix is a translation vector. The following table demonstrates the transformation matrix configuration, where R = Rotation and T = Translation:
矩阵的前面三列确定缩放和旋转。矩阵的第四列是一个平移矢量。下面的表格演示转换矩阵配置,R = 旋转而 T = 平移:
To transform an object, first initialize a Matrix3d object. You can initialize the transformation matrix using an array of doubles or starting with a matrix in which represents the World coordinate system or a user coordinate system. Once initialized, you then use the functions of the Matrix3d object to modify the scaling, rotation, or displacement transformation of the matrix.
要转换一个对象,首先要初始化一个 Matrix3d 对象。用户可以使用一个双精度整数数组或以一个表示世界坐标系或用户坐标系的矩阵来初始化转换矩阵。一旦初始化完成,就可以使用 Matrix3d 对象的函数用于修改缩放、旋转或平移的转换矩阵。
After the transformation matrix is complete, apply the matrix to the object using the TransformBy method. The following line of code demonstrates applying a matrix (dMatrix) to an object (acObj):
变换矩阵完成后,利用 TransformBy 方法应用这个矩阵到对象中。下面的代码行演示应用一个矩阵(dMatrix) 到一个对象(acObj):
VB.NET
acObj.TransformBy(dMatrix)
C#
acObj.TransformBy(dMatrix);
The following shows a single data array to define a transformation matrix, assigned to the variable dMatrix, which will rotate an entity by 90 degrees about the point (0, 0, 0).
下面显示一个用于定义一个转换矩阵的单个数据数组,并赋值给变量 dMatrix,它将图元绕点 (0,0,0)旋转90度。
Rotation Matrix: 90 degrees about point (0, 0, 0) 旋转矩阵:绕点(0,0,0)旋转90度 |
|||
---|---|---|---|
0.0 |
-1.0 |
0.0 |
0.0 |
1.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
1.0 |
0.0 |
0.0 |
0.0 |
0.0 |
1.0 |
Initialize a transformation matrix with a data array in which contains the information to rotate an object 90 degrees.
用一个数据组被始化一个转换矩阵,它包含旋转一个对象90度的信息。
Dim dMatrix(0 To 15) As Double
dMatrix(0) = 0.0
dMatrix(1) = -1.0
dMatrix(2) = 0.0
dMatrix(3) = 0.0
dMatrix(4) = 1.0
dMatrix(5) = 0.0
dMatrix(6) = 0.0
dMatrix(7) = 0.0
dMatrix(8) = 0.0
dMatrix(9) = 0.0
dMatrix(10) = 1.0
dMatrix(11) = 0.0
dMatrix(12) = 0.0
dMatrix(13) = 0.0
dMatrix(14) = 0.0
dMatrix(15) = 1.0
Dim acMat3d As Matrix3d = New Matrix3d(dMatrix)
Initialize a transformation matrix without a data array and use the Rotation function to return a transformation matrix that rotates an object 90 degrees.
初始化一个没有数据组的转换矩阵,并使用 Rotation 函数返回一个将一个对象旋转90度的转换矩阵。
Dim acMat3d As Matrix3d = New Matrix3d()
Matrix3d.Rotation(Math.PI / 2, _
curUCS.Zaxis, _
New Point3d(0, 0, 0))
Initialize a transformation matrix with a data array in which contains the information to rotate an object 90 degrees.
用一个数据组被始化一个转换矩阵,它包含旋转一个对象90度的信息。
double[] dMatrix = new double[16];
dMatrix[0] = 0.0;
dMatrix[1] = -1.0;
dMatrix[2] = 0.0;
dMatrix[3] = 0.0;
dMatrix[4] = 1.0;
dMatrix[5] = 0.0;
dMatrix[6] = 0.0;
dMatrix[7] = 0.0;
dMatrix[8] = 0.0;
dMatrix[9] = 0.0;
dMatrix[10] = 1.0;
dMatrix[11] = 0.0;
dMatrix[12] = 0.0;
dMatrix[13] = 0.0;
dMatrix[14] = 0.0;
dMatrix[15] = 1.0;
Matrix3d acMat3d = new Matrix3d(dMatrix);
Initialize a transformation matrix without a data array and use the Rotation function to return a transformation matrix that rotates an object 90 degrees.
初始化一个没有数据组的转换矩阵,并使用 Rotation 函数返回一个将一个对象旋转90度的转换矩阵。
Matrix3d acMat3d = new Matrix3d();
acMat3d = Matrix3d.Rotation(Math.PI / 2,
curUCS.Zaxis,
new Point3d(0, 0, 0));
The following are more examples of transformation matrices:
下面有很多转换矩阵的例子:
|
Translation Matrix: move an entity by (10, 10, 0) 转换矩阵:将图元移到 (10, 10, 0) |
|||
---|---|---|---|
1.0 |
0.0 |
0.0 |
10.0 |
0.0 |
1.0 |
0.0 |
10.0 |
0.0 |
0.0 |
1.0 |
0.0 |
0.0 |
0.0 |
0.0 |
1.0 |
Scaling Matrix: scale by 10,10 at point (0, 0, 0) 缩放矩阵:在点 (0, 0, 0) 上按 10,10 进行缩放 |
|||
---|---|---|---|
10.0 |
0.0 |
0.0 |
0.0 |
0.0 |
10.0 |
0.0 |
0.0 |
0.0 |
0.0 |
10.0 |
0.0 |
0.0 |
0.0 |
0.0 |
1.0 |