Deriving a Matrix from LOC/ROT/SCALE? 2.49

Hi All,

I have point in space LOC/ROT/SCALE that I want to convert the point to a matrix.


def returnMatrix (lx,ly,lz,rx,ry,rz,sx,sy,sz):
    result = ?? #Magic math code goes here
    return result

Can anyone point me in the right direction or posts some code?

Thanks!

Im using the matrix approach to construct the required object’s matrix… It’s more conprehensive, I think.

Sooo it’s a matter of constructing some matrices (for location, rotation, scale + the BASE unit matrix 4x4), then multiply them appropriately:

def Eu_degr(eu):  # eu in radians
    eu_x,eu_y,eu_z = eu[0],eu[1],eu[2]
    eu_x = math.degrees(eu_x)
    eu_y = math.degrees(eu_y)
    eu_z = math.degrees(eu_z)
    eu_degr = Mathutils.Euler(eu_x,eu_y,eu_z)
    return eu_degr

def Eu_rad(eu):  # eu in degrees
    eu_x,eu_y,eu_z = eu[0],eu[1],eu[2]
    eu_x = math.radians(eu_x)
    eu_y = math.radians(eu_y)
    eu_z = math.radians(eu_z)
    eu_rad = Mathutils.Euler(eu_x,eu_y,eu_z)
    return eu_rad

def Make_object_matrix(lx,ly,lz,rx,ry,rz,sx,sy,sz):
    loc_mat = Mathutils.Matrix([0,0,0,0],[0,0,0,0],[0,0,0,0],[lx,ly,lz,0])
    scale_mat = Mathutils.Matrix([sx,0,0,0],[0,sy,0,0],[0,0,sz,0],[0,0,0,1])
    eu = Mathutils.Euler(rx,ry,rz)
    eu_degr = Eu_degr(eu)  # in case (rx,ry,rz) are in radians
    rot_mat = eu_degr.toMatrix()
    new_mat = rot_mat.resize4x4()
    ob_mat = new_mat*scale_mat+loc_mat
    return ob_mat

Eu_degr and Eu_rad are AUX functions to convert Eulers/rot or lists/tuples into Eulers in degrees or rot in radians. For your task, only the first one is needed :cool:

You may wish accelerate the process by directly writing values in the resulting matrix BUT… you need to know what you’re doing and be precise and very careful :wink:

Regards,

Thank you Abidos!

I am going to give that a try, I am still fairly math challenged.:eek:

I know this may sound silly, but how do I do the reverse.

Say I have an empty traveling along a path via a followpath constraint.

I can get the matrix of the empty in worldspace but how do I extract the LOC/ROT from the matrix?

I think I get it now, that is what the translationPart of the matrix is about.


myVector = tempMatrix.translationPart()
x = myVector[0]
y = myVector[1]
z = myVector[2]

There’s good API for that… Suppose your matrix 4x4 is called mat. Then you have:

loc = mat.translationPart()  # vector
rot_mat = mat.rotationPart()  # matrix
scale = mat.scalePart()  # vector

Regards,