CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

转换对象 (.NET)

2023-1-1 13:53| 发布者: admin| 查看: 351| 评论: 0|来自: AutoCAD

您可以使用由对象和方法表示的 4 x 4 转换矩阵移动、缩放、旋转和镜像对象。还可以使用该方法创建实体的副本,然后将转换应用于该副本。对象是命名空间的一部分。Matrix3dTransformByGetTransformedCopyMatrix3dGeometry

矩阵的前三列指定比例和旋转。矩阵的第四列是平移向量。下表演示了转换矩阵配置,其中 R = 旋转,T = 平移:

转换矩阵配置

R00

R01

R02

T0

R10

R11

R12

T1

R20

R21

R22

T2

0

0

0

1

要转换对象,请先初始化对象。您可以使用双精度数组或从表示世界坐标系或用户坐标系的矩阵开始初始化变换矩阵。初始化后,您可以使用对象的函数修改矩阵的缩放、旋转或置换变换。Matrix3dMatrix3d

转换矩阵完成后,使用该方法将矩阵应用于对象。以下代码行演示如何将矩阵 () 应用于对象 ():TransformBydMatrixacObj

VB.NET
acObj.TransformBy(dMatrix)
C#
acObj.TransformBy(dMatrix);

旋转矩阵示例

下面显示了单个数据数组,用于定义分配给变量的转换矩阵,该矩阵将围绕点 (0, 0, 0) 将实体旋转 90 度。dMatrix

旋转矩阵:围绕点 (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

VB.NET

使用数据数组初始化转换矩阵,其中包含将对象旋转 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)

初始化没有数据数组的转换矩阵,并使用函数返回将对象旋转 90 度的转换矩阵。Rotation

Dim acMat3d As Matrix3d = New Matrix3d()
 
Matrix3d.Rotation(Math.PI / 2, _
                  curUCS.Zaxis, _
                  New Point3d(0, 0, 0))

C#

Initialize a transformation matrix with a data array in which contains the information to rotate an object 90 degrees.

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 function to return a transformation matrix that rotates an object 90 degrees. Rotation

Matrix3d acMat3d = new Matrix3d();
 
acMat3d = Matrix3d.Rotation(Math.PI / 2,
                            curUCS.Zaxis,
                            new Point3d(0, 0, 0));

Additional examples of transformation matrices

The following are more examples of transformation matrices:

Rotation Matrix: 45 degrees about point (5, 5, 0)

0.707107

-0.707107

0.0

5.0

0.707107

0.707107

0.0

-2.071068

0.0

0.0

1.0

0.0

0.0

0.0

0.0

1.0

Translation Matrix: move an entity by (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

缩放矩阵:在点 (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

缩放矩阵:在点 (2, 2, 0) 缩放 10,10

10.0

0.0

0.0

-18.0

0.0

10.0

0.0

-18.0

0.0

0.0

10.0

0.0

0.0

0.0

0.0

1.0


路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:51

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部