Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotating a vector is using left-multiplication. #101

Open
kaufManu opened this issue Sep 1, 2020 · 2 comments
Open

Rotating a vector is using left-multiplication. #101

kaufManu opened this issue Sep 1, 2020 · 2 comments

Comments

@kaufManu
Copy link

kaufManu commented Sep 1, 2020

I'm not sure if this is an issue or not, but the following code snippet just confused me a lot.

I am creating a rotation matrix that rotates around z by 90 degrees. This means, when we rotate the x vector [1.0, 0.0, 0.0] by this rotation I would expect to get the y vector [0.0, 1.0, 0.0]. As you can see from the code snippet below however, using pyrr matrices and vectors, we obtain the negative y vector, i.e. [0.0, -1.0, 0.0]. This is because pyrr is applying the vector v from the left. So when converting a numpy rotation matrix to pyrr.Matrix33 we should pass in its transpose to get the same behavior.

May be this is what the documentation means by saying matrices are row-major. But in any case, this is extremely confusing because when printing the pyrr rotation matrix m the printout is exactly the same as when printing the numpy rotation matrix rot.

import cv2
import numpy as np
from pyrr import Matrix33
from pyrr.matrix33 import apply_to_vector

aa = np.array([0.0, 0.0, np.pi/2])
rot = cv2.Rodrigues(aa)[0]

v = np.array([1.0, 0.0, 0.0])[:, np.newaxis]
v_prime = np.matmul(rot, v)
print('rotation matrix', rot)
print('v_prime', v_prime)

m = Matrix33(rot)
v_prime_pyrr = apply_to_vector(m, v.squeeze())
print('rotation matrix', m)
print('v_prime_pyrr', v_prime_pyrr)
@adamlwgriffiths
Copy link
Owner

adamlwgriffiths commented Sep 2, 2020 via email

@adamlwgriffiths
Copy link
Owner

adamlwgriffiths commented Sep 2, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants