Rotation of component in 3D space
Posted: Wed Oct 18, 2023 7:11 am
Hi guys,
I want to place a component in assembly with particular orientation w.r.t. to origin axes. I have managed to successfully rotate a component about 1 axis by getting a RotationMatrix, and applying SetTransformAndSolve3 to the component.
However, if I would like to place a component in a 3D space, with some arbitrary angle between X, Y and Z axes, how should I do it?
My idea was to get axis rotation matrices for each rotation, and then apply each rotation to component resulting in a correctly placed component, which doesn't happen. It places the component in the last rotation that I called.
Do I have to multiply the matrices (not sure about if the maths between transformations, element-wise, matrix-wise, or if it's even sensible to multiply them) for each rotation and supply them to component with SetTransformAndSolve3?
Thanks!
I want to place a component in assembly with particular orientation w.r.t. to origin axes. I have managed to successfully rotate a component about 1 axis by getting a RotationMatrix, and applying SetTransformAndSolve3 to the component.
Code: Select all
Function RotXMatrix(ByRef swComp As Component2, ByRef swMathUtil As MathUtility, ByVal angleX As Double) As MathTransform
Dim TransformData() As Double
ReDim TransformData(0 To 15) As Double
TransformData(0) = 1 ' X-axis rotational components
TransformData(1) = 0
TransformData(2) = 0
TransformData(3) = 0 ' Y-axis rotational components
TransformData(4) = Math.Cos(angleX * pi / 180)
TransformData(5) = Math.Sin(angleX * pi / 180) * (-1)
TransformData(6) = 0 ' Z-axis rotational components
TransformData(7) = Math.Sin(angleX * pi / 180)
TransformData(8) = Math.Cos(angleX * pi / 180)
TransformData(9) = 0 ' X-translation
TransformData(10) = 0 ' Y-translation
TransformData(11) = 0 ' Z-translation
TransformData(12) = 1 ' Scaling factor
TransformData(13) = 0 ' Unusued
TransformData(14) = 0 ' Unusued
TransformData(15) = 0 ' Unusued
Dim TransformDataVariant As Variant
TransformDataVariant = TransformData
Set RotXMatrix = swMathUtil.CreateTransform((TransformDataVariant))
End Function
My idea was to get axis rotation matrices for each rotation, and then apply each rotation to component resulting in a correctly placed component, which doesn't happen. It places the component in the last rotation that I called.
Do I have to multiply the matrices (not sure about if the maths between transformations, element-wise, matrix-wise, or if it's even sensible to multiply them) for each rotation and supply them to component with SetTransformAndSolve3?
Thanks!