moble / quaternionic

Interpret numpy arrays as quaternionic arrays with numba acceleration
MIT License
84 stars 7 forks source link

Idea: implement matmul as rotation #35

Closed evbernardes closed 2 years ago

evbernardes commented 2 years ago

Since matmul for quaternion type arrays isn't implemented, it would be nice to have it implemented as rotation of a vector. Example: If I have an array of size (N x 3) or just even (1 x 3) representing a 3D vector and an array (N x 4) representing the quaternion, instead of having to type: v2 = (q * quaternionic.array.from_vector_part(v1) * q.inverse).vector It would be nice to just type instead: v2 = q @ v1

moble commented 2 years ago

Thanks for the suggestion. However, I don't want to make matmul a synonym for rotation, because multiplication of matrices with quaternion elements is actually a thing, and I wouldn't want to deceive people into thinking they can multiply quaternion matrices. It's important to remember that people (myself included) do use quaternions for things other than just rotations — though rotations are certainly the most common application.

As for having a simpler syntax, you can just use v2 = q.rotate(v1), which seems a lot clearer IMO. However, I realize that I didn't put that in the README, which is an oversight I've fixed now.

evbernardes commented 2 years ago

Fair enough, and yeah somehow I didn't think of looking for a "rotate" function! Thanks for your reply, and most of all, thanks for this awesome library!