PDA

View Full Version : TransformationMatrix



jwanstaett
2004-08-24, 08:26 PM
how do i calculat the data that go in the TransformationMatrix to be use by TransformBy method

exp: need TransformationMatrix rotation 30 degres x axis, rotation 10 degrees z axis, scale 10 @ 3,3,3

jwanstaett
2005-10-04, 03:48 PM
Will it looks like no one use the TransformationMatrix in AutoCAD one year and no reply

Ed Jobe
2005-10-04, 04:26 PM
Will it looks like no one use the TransformationMatrix in AutoCAD one year and no reply
Sorry John...looks like that is an accurate assumption. I think that's one of the least understood functions in acad. I didn't take calculus so it's kind of foreign to me too. Back in the guilds, Bobby Jones dug around and came up with some good explanations but I haven't seen him around for awhile. Try this Google search (http://www.google.com/search?hl=en&lr=&q=TransformBy+group%3Aautodesk.autocad.customization.vba&btnG=Search) and see if it helps.

Opie
2005-10-04, 04:33 PM
Sorry John...looks like that is an accurate assumption. I think that's one of the least understood functions in acad. I didn't take calculus so it's kind of foreign to me too. Back in the guilds, Bobby Jones dug around and came up with some good explanations but I haven't seen him around for awhile. Try this Google search (www.gTransformBy group:autodesk.autocad.customization.vba) and see if it helps.
Your link doesn't work. Did you mean this search (http://www.google.com/search?hl=en&lr=&q=TransformBy+group+autodesk.autocad.customization.vba&btnG=Search)?

Ed Jobe
2005-10-04, 04:56 PM
I just did a copy/paste. Go figure? Your search was close, but didn't include a colon between group and the name. I fixed my original post.

Opie
2005-10-04, 06:35 PM
I just did a copy/paste. Go figure? Your search was close, but didn't include a colon between group and the name. I fixed my original post.
I had removed the : due to the following response from google

group:autodesk.autocad.customization.vba was dropped from your search because it is not supported for this type of search.

Ed Jobe
2005-10-04, 06:54 PM
I don't understand that one! worked for me. :confused:

Opie
2005-10-04, 06:58 PM
I don't understand that one! worked for me. :confused:
See the attached image.

Ed Jobe
2005-10-04, 07:43 PM
I see what you're doing now. Once you click on the search link I gave you, you need to click on the Groups tab at the top of the page. You can use those links, to filter your search for that specific area without having to redo your search.

Opie
2005-10-04, 07:53 PM
Then I guess this (http://groups.google.com/groups?hl=en&lr=&q=TransformBy%20group%3Aautodesk.autocad.customization.vba&btnG=Search&sa=N&tab=wg) is the link that is needed.

jwanstaett
2005-10-05, 02:47 PM
well I did my home work and here the function I how use for making TransformationMatrix
Rotation and scaling in your programs then the function may help

note: some function call orther function so you need to add all the function to you progarm
add the function use the const DegTor so it will need to be put a a Module



Const DegTor As Double = 1.74532925199433E-02

'This Funtion return the Product of
'MatrixA MatrixB
'The Product of two Matrix will get one Matrix
'that dose the same as use TransformBy
'with bouth matrix
Public Function MatrixProduct(MatrixA, MatrixB)
Dim m, n1, n2, r, i, j, j1 As Integer
Dim Product() As Double
m = UBound(MatrixA, 1)
n1 = UBound(MatrixA, 2)
n2 = UBound(MatrixB, 1)
r = UBound(MatrixB, 2)
If n1 <> n2 Then Exit Function
ReDim Product(m, r)
For i = 0 To m
For j = 0 To r
Product(i, j) = 0
For j1 = 0 To n1
Product(i, j) = Product(i, j) + (MatrixA(i, j1) * MatrixB(j1, j))
Next
Next
Next
MatrixProduct = Product
End Function

'This function will retutn TransformationMatrix
'to be use by TransformBy
'to scale by vScale
Public Function SetScaleMatrix(vScale As Double, Optional vX As Double = 0, Optional vY As Double = 0, Optional vZ As Double = 0)
Dim TepMatrix
Dim ScaleMatrix(3, 3) As Double
ScaleMatrix(0, 0) = vScale
ScaleMatrix(1, 1) = vScale
ScaleMatrix(2, 2) = vScale
ScaleMatrix(3, 3) = 1
TepMatrix = MatrixProduct(ScaleMatrix, SetTranslationMatrix(-vX, -vY, -vZ))
TepMatrix = MatrixProduct(SetTranslationMatrix(vX, vY, vZ), TepMatrix)
SetScaleMatrix = TepMatrix
End Function

'This function will retutn TransformationMatrix
'to be use by TransformBy
'of the point vX,Vy,vZ
Public Function SetTranslationMatrix(vX As Double, vY As Double, vZ As Double)
Dim vMatrix(3, 3) As Double
vMatrix(3, 3) = 1
vMatrix(0, 3) = vX
vMatrix(1, 3) = vY
vMatrix(2, 3) = vZ
vMatrix(1, 1) = 1
vMatrix(2, 2) = 1
vMatrix(0, 0) = 1
SetTranslationMatrix = vMatrix
End Function

'This function will retutn TransformationMatrix
'to be use by TransformBy
'to Rotation on Z axis ZRotatins deg.
'vX,Vy,VZ is the base point
Public Function SetRotationZ(ZRotation As Double, Optional vX As Double = 0, Optional vY As Double = 0, Optional vZ As Double = 0)
Dim TepMatrix
Dim vMatrix(3, 3) As Double
vMatrix(3, 3) = 1
vMatrix(0, 0) = Cos(ZRotation * DegTor)
vMatrix(0, 1) = -Sin(ZRotation * DegTor)
vMatrix(1, 0) = Sin(ZRotation * DegTor)
vMatrix(1, 1) = Cos(ZRotation * DegTor)
vMatrix(2, 2) = 1
TepMatrix = MatrixProduct(vMatrix, SetTranslationMatrix(-vX, -vY, -vZ))
TepMatrix = MatrixProduct(SetTranslationMatrix(vX, vY, vZ), TepMatrix)
SetRotationZ = TepMatrix
End Function

'This function will retutn TransformationMatrix
'to be use by TransformBy
'to Rotation on x axis XRotation deg.
'vX,Vy,VZ is the base point
Public Function SetRotationX(XRotation As Double, Optional vX As Double = 0, Optional vY As Double = 0, Optional vZ As Double = 0)
Dim TepMatrix
Dim vMatrix(3, 3) As Double
vMatrix(3, 3) = 1
vMatrix(1, 1) = Cos(XRotation * DegTor)
vMatrix(1, 2) = -Sin(XRotation * DegTor)
vMatrix(2, 1) = Sin(XRotation * DegTor)
vMatrix(2, 2) = Cos(XRotation * DegTor)
vMatrix(1, 1) = 1
TepMatrix = MatrixProduct(vMatrix, SetTranslationMatrix(-vX, -vY, -vZ))
TepMatrix = MatrixProduct(SetTranslationMatrix(vX, vY, vZ), TepMatrix)
SetRotationX = TepMatrix
End Function

'This function will retutn TransformationMatrix
'to be use by TransformBy
'to Rotation on Y axis YRotation deg.
'vX,Vy,VZ is the base point
Public Function SetRotationY(YRotation As Double, Optional vX As Double = 0, Optional vY As Double = 0, Optional vZ As Double = 0)
Dim TepMatrix
Dim vMatrix(3, 3) As Double
vMatrix(1, 1) = 1
vMatrix(0, 0) = Cos(YRotation * DegTor)
vMatrix(2, 1) = -Sin(YRotation * DegTor)
vMatrix(0, 2) = Sin(YRotation * DegTor)
vMatrix(2, 2) = Cos(YRotation * DegTor)
vMatrix(3, 3) = 1

TepMatrix = MatrixProduct(vMatrix, SetTranslationMatrix(-vX, -vY, -vZ))
TepMatrix = MatrixProduct(SetTranslationMatrix(vX, vY, vZ), TepMatrix)
SetRotationY = TepMatrix
End Function

'This Function will return a TransformationMatrix
'to be use by TransformBy
'Zrotation,XRotation,Yrotation are in deg
'vScale is the scale
'vX,vY,vX are the point use as the base for rotations and scaleing

Public Function MakeMatrix(ZRotation As Double, Optional XRotation As Double = 0, Optional YRotation As Double = 0, Optional vScale As Double = 1, Optional vX As Double = 0, Optional vY As Double = 0, Optional vZ As Double = 0)
Dim TepMatrix
TepMatrix = SetScaleMatrix(vScale, vX, vY, vZ)
TepMatrix = MatrixProduct(SetRotationZ(ZRotation, vX, vY, vZ), TepMatrix)
TepMatrix = MatrixProduct(SetRotationX(XRotation, vX, vY, vZ), TepMatrix)
TepMatrix = MatrixProduct(SetRotationY(YRotation, vX, vY, vZ), TepMatrix)
MakeMatrix = TepMatrix
End Function



PS. If you use this Code I would Like to know how it work so plase post info. here on how you use the code.