mathutils.Euler.py 900 B

123456789101112131415161718192021222324252627282930313233
  1. import mathutils
  2. import math
  3. # create a new euler with default axis rotation order
  4. eul = mathutils.Euler((0.0, math.radians(45.0), 0.0), 'XYZ')
  5. # rotate the euler
  6. eul.rotate_axis('Z', math.radians(10.0))
  7. # you can access its components by attribute or index
  8. print("Euler X", eul.x)
  9. print("Euler Y", eul[1])
  10. print("Euler Z", eul[-1])
  11. # components of an existing euler can be set
  12. eul[:] = 1.0, 2.0, 3.0
  13. # components of an existing euler can use slice notation to get a tuple
  14. print("Values: %f, %f, %f" % eul[:])
  15. # the order can be set at any time too
  16. eul.order = 'ZYX'
  17. # eulers can be used to rotate vectors
  18. vec = mathutils.Vector((0.0, 0.0, 1.0))
  19. vec.rotate(eul)
  20. # often its useful to convert the euler into a matrix so it can be used as
  21. # transformations with more flexibility
  22. mat_rot = eul.to_matrix()
  23. mat_loc = mathutils.Matrix.Translation((2.0, 3.0, 4.0))
  24. mat = mat_loc @ mat_rot.to_4x4()