4 x 4 変換マトリックスを指定して、オブジェクトを移動、尺度変更、または回転させます。
サポートされているプラットフォーム: Windows のみ
VBA:
object.TransformBy TransformationMatrix
タイプ: すべての図形オブジェクト、AttributeReference
このメソッドが適用されるオブジェクト。
アクセス: 入力のみ
タイプ: バリアント型(4 x 4 要素の倍精度浮動小数点数型配列)
実行する変換を指定する 4x4 マトリックス。
戻り値はありません。
変換マトリックスの構成を次に示します(R = 回転、T = 平行移動)。
R00 | R01 | R02 | T0 |
R10 | R11 | R12 | T1 |
R20 | R21 | R22 | T2 |
0 | 0 | 0 | 1 |
このメソッドは、変換マトリックスが正しくない場合は、エラーを戻します。
このメソッドのコード例には、変換マトリックスのサンプルがあります。
VBA:
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)))) )