bhreathn711
bhreathn711

Reputation: 79

Get matrix product of 3 matrices

I have 3, 3X3 matrices stored in numpy arrays. I want to get the product, to compute a rotation matrix.

Currently what I am doing is rotation_matrix = (a * b * c) but I don't know if this is the correct way to multiply matrices - should I be using .dot I have also tried with rotation_matrix = pre_rotation.dot(result_pre_tilt).dot(post_rotation)

and rotation_matrix = np.multiply(result_pre_tilt, pre_rotation, post_rotation)

a = np.array(
[[-0.25091924  0.         -0.        ]
[-0.         -0.35485339  0.        ]
[ 0.          0.          0.70710678]])

b = np.array(
[[ 0.10040533 -0.          0.        ]
[ 0.          0.28953198 -0.        ]
[ 0.          0.          0.31056766]])

c = np.array(
[[  6.12323400e-17   0.00000000e+00  -1.00000000e+00]
[  0.00000000e+00   1.00000000e+00   0.00000000e+00]
[  1.00000000e+00   0.00000000e+00   6.12323400e-17]])

Upvotes: 0

Views: 8052

Answers (1)

heltonbiker
heltonbiker

Reputation: 27615

You can try using dot like this:

final= numpy.dot(tilt_matrix, (numpy.dot(rotation_matrix, original))

Things to consider:

  1. numpy.dot is a function, not a method (not possible to call A.dot(B), call np.dot(A, B) instead);
  2. The order matters - if you are not getting the right result, try changing the order. Sometimes you need to translate first and then rotate, sometimes the opposite. Depends on each case;
  3. The left matrix column number must be the same size of the right matrix row number, for 2D matrices.

Upvotes: 2

Related Questions