How to do the line marked with # <----
in a more direct way?
In the program, each row of x
is coordinates of a point, rot_mat[0]
and rot_mat[1]
are two rotation matrices. The program rotates x
by each rotation matrix.
Changing the order of multiplication between each rotation matrix and the coordinates is fine, if it makes things simpler. I want to have each row of x
or the result representing coordinate of a point.
The result should match the checks.
Program:
# Rotation of coordinates of 4 points by
# each of the 2 rotation matrices.
import numpy as np
from scipy.stats import special_ortho_group
rot_mats = special_ortho_group.rvs(dim=3, size=2) # 2 x 3 x 3
x = np.arange(12).reshape(4, 3)
result = np.dot(rot_mats, x.T).transpose((0, 2, 1)) # <----
print("---- result ----")
print(result)
print("---- check ----")
print(np.dot(x, rot_mats[0].T))
print(np.dot(x, rot_mats[1].T))
Result:
---- result ----
[[[ 0.20382264 1.15744672 1.90230739]
[ -2.68064533 3.71537598 5.38610452]
[ -5.56511329 6.27330525 8.86990165]
[ -8.44958126 8.83123451 12.35369878]]
[[ 1.86544623 0.53905202 -1.10884323]
[ 5.59236544 -1.62845022 -4.00918928]
[ 9.31928465 -3.79595246 -6.90953533]
[ 13.04620386 -5.9634547 -9.80988139]]]
---- check ----
[[ 0.20382264 1.15744672 1.90230739]
[ -2.68064533 3.71537598 5.38610452]
[ -5.56511329 6.27330525 8.86990165]
[ -8.44958126 8.83123451 12.35369878]]
[[ 1.86544623 0.53905202 -1.10884323]
[ 5.59236544 -1.62845022 -4.00918928]
[ 9.31928465 -3.79595246 -6.90953533]
[ 13.04620386 -5.9634547 -9.80988139]]