Home > Blockchain >  Rotate Transformation Matrix Around Point
Rotate Transformation Matrix Around Point

Time:09-01

I have a 4x4 transoformation matrix T0 as a starting pose.

Now I want to rotate T0 with an 3x3 rotation matrix R around a center point to get a new pose T1.

import numpy as np

T0 = np.eye(4)
R = np.array([[0.98480775, 0., 0.17364818],
              [0., 1., 0.],
              [-0.17364818, 0., 0.98480775]])
center = np.array([-2.00628613e-02, -1.26855529e 00, -3.45331795e 01])

# T1 = ?

How to calculate T1?

CodePudding user response:

Check out https://math.stackexchange.com/questions/2093314/rotation-matrix-of-rotation-around-a-point-other-than-the-origin and remember that matrix multiplication in numpy uses matmul https://numpy.org/doc/stable/reference/generated/numpy.matmul.html.

I'm not sure why your original matrix is a 4x4 if you're in 3d space?

CodePudding user response:

The solution is described here. And the working code is below:

import numpy as np

T0 = np.eye(4)
R = np.array([[0.98480775, 0., 0.17364818],
              [0., 1., 0.],
              [-0.17364818, 0., 0.98480775]])
center = np.array([-2.00628613e-02, -1.26855529e 00, -3.45331795e 01])

T = np.eye(4)
T[:3, :3] = R
T[:3, 3] = center - np.matmul(R, center)

T1 = np.matmul(T, T0)
  • Related