2
$\begingroup$

So I've got the matrix values in a row format like this.

enter image description here

My code:

import bpy
obj = bpy.context.object

f.write(str(obj.matrix_world))

However I'm not quite sure how I can make this write for X, Y, and Z individually. Specifically I need the rotation values which are setup like this in the grid.

$$R_x=\begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & \cos\theta & -\sin\theta & 0\\ 0 & \sin\theta & \cos\theta & 0\\ 0 & 0 & 0 & 1 \end{bmatrix}$$

$$R_y=\begin{bmatrix} \cos\theta & 0 & \sin\theta & 0\\ 0 & 1 & 0 & 0\\ -\sin\theta & 0 & \cos\theta & 0\\ 0 & 0 & 0 & 1 \end{bmatrix}$$

$$R_z=\begin{bmatrix} \cos\theta & -\sin\theta & 0 & 0\\ \sin\theta & \cos\theta & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1 \end{bmatrix}$$

$\endgroup$
2
$\begingroup$

How to make the three basic rotation matrices rotate around the x, y, or z axis.

import bpy
from math import pi
from mathutils import Vector, Matrix, Euler

theta = pi / 6

for i in range(3):
    angle = Vector()
    angle[i] = theta
    mat = Euler(angle, 'XYZ').to_matrix().to_4x4()
    print(mat, "\n")

Or directly

from math import pi, sin, cos
from mathutils import Matrix

theta = pi / 6
s = sin(theta)
c = cos(theta)

mat = Matrix()
mat[1][1] = c
mat[1][2] =-s
mat[2][1] = s
mat[2][2] = c

print(mat, "\n")
$\endgroup$
  • 2
    $\begingroup$ Suggest creating a 4x4 rotation matrix of theta radians around x axis via mat = Matrix.Rotation(theta, 4, 'X') $\endgroup$ – batFINGER Nov 18 '17 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.