mathutil matrix how to

@rarebit
Why not using math.radians?
Why not use Matrix.Rotation(radians(45),3,‘Z’) ?

LOL, as I explained, that’s mainly a link to an example about a function Ricardo can amend to multiply matrices of arbitrary sizes… He must have asked in a msg since i’m not seeing on this thread…

That tutorial isn’t mine! It’s just an old tutorial I came across earlier, but it does explain rotations very well!

However I personally try to use radians instead of degrees, unless of course there is a user interface which dictates some won’t understand!

here example using angles addition with euler angles


 
import bpy
 
import mathutils
from math import *
from bpy.props import *
 
#  First angle
 
xag1=30      # Angle in degrees
xag1r=xag1*pi/180
yag1=30
yag1r=yag1*pi/180
zag1=45
zag1r=zag1*pi/180
 
print ('z angle =',zag1,' Deg  =',zag1r,' Rad')
print ()
 
eu1=[xag1r,yag1r,zag1r]
eud=[xag1,yag1,zag1]
 
print ('EU1 angle = ',eu1,' Radians')
print ('EU1 angle = ',xag1,'Deg  ',yag1 , 'Deg   ',zag1,'Deg')
print ()
 
#  Second angle
 
xag2=36      # Angle in degrees
xag2r=xag2*pi/180
yag2=72
yag2r=yag2*pi/180
zag2=15
zag2r=zag1*pi/180
 
eu2=[xag2r,yag2r,zag2r]
eu2d=[xag2,yag2,zag2]
 
print ('EU2 angle = ',eu2,' Radians')
print ('EU2 angle = ',xag2,'Deg  ',yag2 , 'Deg   ',zag2,'Deg')
print ()
 
 
eu_x1,eu_y1,eu_z1 = eu1[0],eu1[1],eu1[2]
eu_x2,eu_y2,eu_z2 = eu2[0],eu2[1],eu2[2]
print ()
print ('enew = EU1+ EU2   angle  ')
print ()
print ('mathutils.Euler((eu_x1+eu_x2,eu_y1+eu_y2,eu_z1+eu_z2),\'XYZ\') ')
eu_new = mathutils.Euler((eu_x1+eu_x2,eu_y1+eu_y2,eu_z1+eu_z2),'XYZ')
 
print ()
print ('Euler Sum angle =  eu_new angle  Radians = ',eu_new)
print ()
print ('Euler Sum angle =  eu_new angle Degrees  = ',degrees(eu_new[0]),'Deg',degrees(eu_new[1]),'Deg',degrees(eu_new[2]),'Deg')
print ()
print ('EU1 angle X  = ',xag1,'Deg  ','EU2 angle X  = ',xag2,'Deg  ')
print (' Sum X angle =',xag1+xag2,' = Euler sum = degrees(eu_new[0]) =',degrees(eu_new[0]))
 

now not certain if in this case of addition it would work well to do sequence rotation on an object ?
have to do some testing on this !
but i know that quaternion or matrix addition would work well in this case!

2 - also not certain where these axis angles are use in blender
anyone has example for this?

thanks
happy 2.5

what is the replacement for this

#mat3 = mat.rotation_part()
and this one
odml3.scale_part())

dont’
know may be there is one for the translation too!

this seems to show the rotation from the quaternion i think
but how is it done in 2.6 now ?

does it have to do anything with this

mat= Matrix(((1.0, -0.0, 0.0, -0.0),
(-0.0, 7.549790126404332e-08, -1.0, 0.0),
(0.0, 1.0, 7.549790126404332e-08, -0.0),
(-1.0, -3.000000238418579, 1.999999761581421, 1.0)))

Decompose mat= (Vector((-1.0, -3.000000238418579, 1.999999761581421)), Quaternio
n((0.7071068286895752, -0.7071067690849304, 0.0, 0.0)), Vector((1.0, 1.0, 1.0)))

‘Location’
d1= Vector((-1.0, -3.000000238418579, 1.999999761581421))
‘Rotation’
d2= Quaternion((0.7071068286895752, -0.7071067690849304, 0.0, 0.0))
‘Scale’
d3= Vector((1.0, 1.0, 1.0))

?

thanks
happy 2.5