Solved Matrix/HPB to XYZ and vice versa

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.

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

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

@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.

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

@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.

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

@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!