Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Matrix/HPB to XYZ and vice versa

    Cinema 4D SDK
    python r20
    2
    7
    1.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      sheilan
      last edited by sheilan

      Hello,

      I've got some models in two different softwares, when one is using XYZ rotation and the other (cinema 4d) uses HPB/Matrix.
      I couldn't find a way to get my model's XYZ via Python (only Matrix), so I'm looking to see how can I translate rotation matrix or HPB to XYZ and vice versa.

      Thanks in advance,
      Sheilan.

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        hello,

        what come to my mind is those functions MatrixToHPB and HPBToMatrix

        Or maybe i didn't understood your question.

        Cheers
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        S 1 Reply Last reply Reply Quote 1
        • S
          sheilan @Manuel
          last edited by

          @m_magalhaes Hello,

          You misunderstood. I'm able to get Matrix & HBP but I need XYZ. I'm looking for either MatrixToXYZ or HPBToXYZ (preferably the first one).

          Thanks,
          Sheilan.

          1 Reply Last reply Reply Quote 0
          • ManuelM
            Manuel
            last edited by Manuel

            hello,
            there's different flags you can use in that function, all values are differents.

                m = op.GetMg()
                print c4d.utils.MatrixToHPB(m, order=c4d.ROTATIONORDER_DEFAULT)
                print c4d.utils.MatrixToHPB(m, order=c4d.ROTATIONORDER_XYZGLOBAL)
                print c4d.utils.MatrixToHPB(m, order=c4d.ROTATIONORDER_XYZLOCAL)  
            

            what software are you using ? What are the types of XYZ (vector floats) ?

            Cheers
            Manuel

            MAXON SDK Specialist

            MAXON Registered Developer

            S 1 Reply Last reply Reply Quote 0
            • S
              sheilan @Manuel
              last edited by

              @m_magalhaes

              I tried creating a cube and setting it's HBP manually.
              HBP - 47º 0º 0º
              XYZ - 0º 47º 0º

              and the result is

              Vector(0.82, 0, 0)
              Vector(0, 0.82, 0)
              Vector(0, 0.82, 0)
              

              What I need is a result of Vector float that shows (0.0, 47.0, 0,0) (XYZ) as a result.

              1 Reply Last reply Reply Quote 0
              • ManuelM
                Manuel
                last edited by Manuel

                Angles are always store in radian internally. 47° is the same as 0.820304748437 radians.

                you can convert using this function DegToRad

                I think that's what you have with the flag ROTATIONORDER_XYZGLOBAL

                    m = op.GetMg()
                    # convert the matrix to XYZ
                    xyz =  c4d.utils.MatrixToHPB(m, order=c4d.ROTATIONORDER_XYZGLOBAL)
                
                    # convert from radian to deg
                    for i in xrange(3):
                        xyz[i] = c4d.utils.RadToDeg(xyz[i])
                    
                    print xyz
                    
                

                Cheers
                Manuel

                MAXON SDK Specialist

                MAXON Registered Developer

                S 1 Reply Last reply Reply Quote 1
                • S
                  sheilan @Manuel
                  last edited by

                  @m_magalhaes said in Matrix/HPB to XYZ and vice versa:

                  convert the matrix to XYZ

                  xyz =  c4d.utils.MatrixToHPB(m, order=c4d.ROTATIONORDER_XYZGLOBAL)
                  
                  # convert from radian to deg
                  for i in xrange(3):
                      xyz[i] = c4d.utils.RadToDeg(xyz[i])
                  
                  print xyz
                  

                  Works perfectly. Thanks!

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post