×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Rotation Matrix between CSYS objects

Rotation Matrix between CSYS objects

Rotation Matrix between CSYS objects

(OP)
I would like to be able to identify a 4x4 matrix for rotation/tranlation of a CSYS object to another CSYS object. Is this possible with any NX features? Will I need to do some NXOpen coding for this?

RE: Rotation Matrix between CSYS objects

You want to move an object from a reference csys to a new csys? If so, you can do this in the "move object" command.

If you have a different end goal in mind, we'll need more info...

www.nxjournaling.com

RE: Rotation Matrix between CSYS objects

so basically do you want to know the direction of the three axis of the object CSYS?

RE: Rotation Matrix between CSYS objects

(OP)
I don't want to move anything in NX, but I would like to find a method to get a 4x4 matrix from one CSYS to another CSYS. I am looking for something to display the matrix to the information window so I can copy and paste to another application.

RE: Rotation Matrix between CSYS objects

I don't know of an interactive command that will give you that info, but I'm sure it can be done through NXOpen...

www.nxjournaling.com

RE: Rotation Matrix between CSYS objects

As an example, run the following code on this part file. You can move the csys objects around as desired before running the code; blue is the start csys, green is the destination csys (if you forget, you can turn on the object names in Preferences -> Visualization -> names/borders -> show object names = work view). The line that computes the transformation matrix is highlighted, the rest of the code is just setup and output.

CODE

'run this journal on the supplied "transform_matrix.prt" (NX 8)
'running it on other parts will result in an error, the journal looks for specific objects in the file

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim myStartObject As CoordinateSystem

        For Each tempCsys As CoordinateSystem In workPart.CoordinateSystems
            If tempCsys.Name = "CSYS_START" Then
                myStartObject = tempCsys
            End If
        Next

        Dim startPoint As Point3d = myStartObject.Origin
        Dim startOrientation As NXMatrix = myStartObject.Orientation

        lw.WriteLine("start point")
        lw.WriteLine(startPoint.ToString)
        lw.WriteLine("starting orientation")
        lw.WriteLine(startOrientation.Element.Xx & ", " & startOrientation.Element.Xy & ", " & startOrientation.Element.Xz)
        lw.WriteLine(startOrientation.Element.Yx & ", " & startOrientation.Element.Yy & ", " & startOrientation.Element.Yz)
        lw.WriteLine(startOrientation.Element.Zx & ", " & startOrientation.Element.Zy & ", " & startOrientation.Element.Zz)
        lw.WriteLine("")

        Dim myEndObject As CoordinateSystem

        For Each tempCsys As CoordinateSystem In workPart.CoordinateSystems
            If tempCsys.Name = "CSYS_END" Then
                myEndObject = tempCsys
            End If
        Next

        Dim endPoint As Point3d = myEndObject.Origin
        Dim endOrientation As NXMatrix = myEndObject.Orientation

        lw.WriteLine("end point")
        lw.WriteLine(endPoint.ToString)
        lw.WriteLine("ending orientation")
        lw.WriteLine(endOrientation.Element.Xx & ", " & endOrientation.Element.Xy & ", " & endOrientation.Element.Xz)
        lw.WriteLine(endOrientation.Element.Yx & ", " & endOrientation.Element.Yy & ", " & endOrientation.Element.Yz)
        lw.WriteLine(endOrientation.Element.Zx & ", " & endOrientation.Element.Zy & ", " & endOrientation.Element.Zz)
        lw.WriteLine("")


        Dim fromOrigin() As Double = {startPoint.X, startPoint.Y, startPoint.Z}
        Dim fromXAxis() As Double = {startOrientation.Element.Xx, startOrientation.Element.Xy, startOrientation.Element.Xz}
        Dim fromYAxis() As Double = {startOrientation.Element.Yx, startOrientation.Element.Yy, startOrientation.Element.Yz}

        Dim toOrigin() As Double = {endPoint.X, endPoint.Y, endPoint.Z}
        Dim toXAxis() As Double = {endOrientation.Element.Xx, endOrientation.Element.Xy, endOrientation.Element.Xz}
        Dim toYAxis() As Double = {endOrientation.Element.Yx, endOrientation.Element.Yy, endOrientation.Element.Yz}

        Dim mtx4Transform(15) As Double

        theUfSession.Mtx4.CsysToCsys(fromOrigin, fromXAxis, fromYAxis, toOrigin, toXAxis, toYAxis, mtx4Transform)

        lw.WriteLine("transform matrix")
        lw.WriteLine(mtx4Transform(0) & ", " & mtx4Transform(1) & ", " & mtx4Transform(2) & ", " & mtx4Transform(3))
        lw.WriteLine(mtx4Transform(4) & ", " & mtx4Transform(5) & ", " & mtx4Transform(6) & ", " & mtx4Transform(7))
        lw.WriteLine(mtx4Transform(8) & ", " & mtx4Transform(9) & ", " & mtx4Transform(10) & ", " & mtx4Transform(11))
        lw.WriteLine(mtx4Transform(12) & ", " & mtx4Transform(13) & ", " & mtx4Transform(14) & ", " & mtx4Transform(15))


    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

End Module 

www.nxjournaling.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources