CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

TransformBy Method (ActiveX)

2023-1-4 00:45| 发布者: admin| 查看: 361| 评论: 0|来自: AutoCAD

摘要: 移动、缩放或旋转给定 4x4 转换矩阵的对象。

移动、缩放或旋转给定 4x4 转换矩阵的对象。

支持的平台:仅窗口

签名

工 务 局:

object.TransformBy TransformationMatrix
对象

类型:所有图形对象属性引用

此方法适用的对象。

转换矩阵

访问:仅输入

类型:变体(4x4 双精度数组)

指定要执行的转换的 4x4 矩阵。

返回值(RetVal)

无返回值。

言论

下表演示了转换矩阵配置,其中 R = 旋转,T = 平移:R00

R00 R01 R02 T0
R10 R11 R12 T1
R20 R21 R22 T2
0 0 0 1

如果转换矩阵不正确,此方法将返回错误。

此方法的示例代码中提供了示例转换矩阵。

例子

工 务 局:

Sub Example_TransformBy()
    ' This example creates a line and rotates it 90 degrees
    ' using a transformation matrix.
    
    ' Create a line
    Dim lineObj As AcadLine
    Dim startPt(0 To 2) As Double
    Dim endPt(0 To 2) As Double
    startPt(0) = 2: startPt(1) = 1: startPt(2) = 0
    endPt(0) = 5: endPt(1) = 1: endPt(2) = 0
    Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)
    lineObj.Update
    
    ' Initialize the transMat variable with a transformation matrix
    ' that will rotate an object by 90 degrees about the point(0,0,0)
    ' (More examples of transformation matrices are listed below)
    Dim transMat(0 To 3, 0 To 3) As Double
    transMat(0, 0) = 0#: transMat(0, 1) = -1#: transMat(0, 2) = 0#: transMat(0, 3) = 0#
    transMat(1, 0) = 1#: transMat(1, 1) = 0#: transMat(1, 2) = 0#: transMat(1, 3) = 0#
    transMat(2, 0) = 0#: transMat(2, 1) = 0#: transMat(2, 2) = 1#: transMat(2, 3) = 0#
    transMat(3, 0) = 0#: transMat(3, 1) = 0#: transMat(3, 2) = 0#: transMat(3, 3) = 1#
    
    ' Transform the line using the defined transformation matrix
    MsgBox "Transform the line.", , "TransformBy Example"
    lineObj.TransformBy (transMat)
    ZoomAll
    MsgBox "The line is transformed.", , "TransformBy Example"
    
' More examples of transformation matrices:

' Rotation Matrix: 90 Degrees about point 0,0,0
        ' 0.000000  -1.000000  0.000000  0.000000
        ' 1.000000  0.000000  0.000000  0.000000
        ' 0.000000  0.000000  1.000000  0.000000
        ' 0.000000  0.000000  0.000000  1.000000
        
' Rotation Matrix: 45 Degrees about point 5,5,0
        ' 0.70710678118654  -0.70710678118654  0.000000  5.000000
        ' 0.70710678118654  0.70710678118654  0.000000  -2.071068
        ' 0.000000  0.000000  1.000000  0.000000
        ' 0.000000  0.000000  0.000000  1.000000
        
' Translation Matrix: move an object by 10,10,0
        ' 1.000000  0.000000  0.000000  10.000000
        ' 0.000000  1.000000  0.000000  10.000000
        ' 0.000000  0.000000  1.000000  0.000000
        ' 0.000000  0.000000  0.000000  1.000000

' Scaling Matrix: scale by 10,10 at point 0,0,0
        ' 10.000000  0.000000  0.000000  0.000000
        ' 0.000000  10.000000  0.000000  0.000000
        ' 0.000000  0.000000  10.000000  0.000000
        ' 0.000000  0.000000  0.000000  1.000000
        
' Scaling Matrix: scale by 10 at point 2,2
        ' 10.000000  0.000000  0.000000  -18.000000
        ' 0.000000  10.000000  0.000000  -18.000000
        ' 0.000000  0.000000  10.000000  0.000000
        ' 0.000000  0.000000  0.000000  1.000000
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_TransformBy()
    ;; This example creates a line and rotates it 90 degrees
    ;; using a transformation matrix.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))

    ;; Create a line
    (setq startPt (vlax-3d-point 2 1 0)
          endPt (vlax-3d-point 5 1 0))
    
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq lineObj (vla-AddLine modelSpace startPt endPt))
    (vla-Update lineObj)
    
    ;; Initialize the transMat variable with a transformation matrix
    ;; that will rotate an object by 90 degrees about the point(0,0,0)
    ;; (More examples of transformation matrices are listed below)
    (setq transMat (vlax-tmatrix '((0 -1 0 0)
                                   (1 0 0 0)
                                   (0 0 1 0)
                                   (0 0 0 1))))
    
    ;; Transform the line using the defined transformation matrix
    (alert "Transform the line.")
    (vla-TransformBy lineObj transMat)
    (vla-ZoomAll acadObj)
    (vla-Regen doc acAllViewports)
    (alert "The line is transformed.")
    
;; More examples of transformation matrices:
;; Rotation Matrix: 90 Degrees about point 0,0,0
;    (setq transMat (vlax-tmatrix '((0 -1 0 0)
;                                   (1 0 0 0)
;                                   (0 0 1 0)
;                                   (0 0 0 1))))
        
;; Rotation Matrix: 45 Degrees about point 5,5,0
;    (setq transMat (vlax-tmatrix '((0.70710678118654 -0.70710678118654 0 5)
;                                   (0.70710678118654 0.70710678118654 0 -2.071068)
;                                   (0 0 1 0)
;                                   (0 0 0 1))))
        
;; Translation Matrix: move an object by 10,10,0
;    (setq transMat (vlax-tmatrix '((1 0 0 10)
;                                   (0 1 0 10)
;                                   (0 0 1 0)
;                                   (0 0 0 1))))

;; Scaling Matrix: scale by 10,10 at point 0,0,0
;    (setq transMat (vlax-tmatrix '((10 0 0 0)
;                                   (0 10 0 0)
;                                   (0 0 10 0)
;                                   (0 0 0 1))))
        
;; Scaling Matrix: scale by 10 at point 2,2
;    (setq transMat (vlax-tmatrix '((10 0 0 -18)
;                                   (0 10 0 -18)
;                                   (0 0 10 0)
;                                   (0 0 0 1))))
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-11 23:41

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部