TransformBy Example |
Using Programming Languages other than 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
Comments? |