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

Documentation #29

Closed
andreydung opened this issue Oct 23, 2016 · 3 comments
Closed

Documentation #29

andreydung opened this issue Oct 23, 2016 · 3 comments

Comments

@andreydung
Copy link

How do I rotate a vector, let's say (0, 0, 1), using the quaternion? I couldn't find the function in the documentations (there is a lots of quaternion manipulation, but is there a transform/apply function)?

@moble
Copy link
Owner

moble commented Oct 23, 2016

At the time of this writing, there is no specialized function (though I'll add one in the next week or two). So the way to go for now is to just use quaternion multiplication. For example, if you have a 3-vector v (as a list or numpy array, for example) you can convert it to a quaternion as

V = quaternion.quaternion(0, *v)

Then you can rotate it as

Vprime = R * V * R.conj()

[If you're not sure if R will be precisely normalized, you might want to use R.inv() instead of R.conj().] You can then get just the vector components as a numpy array with

Vprime.vec

This, of course, is relatively slow because the operation count is higher than it needs to be (32 multiplies and 24 adds). I can cut the operation count almost in half (18 multiplies and 12 adds) by using a specialized function. I'll leave this open until I implement that.

@DrHibbitts
Copy link

Has there been any progress on this? the ability to apply Quaternions to vectors is likely to be a key component in any project that uses Quaternions.

@moble
Copy link
Owner

moble commented Nov 22, 2016

As I said above, it is currently possible, it's just that it could be made more efficient. I've been trying to figure out the best approach, because numpy doesn't make this particular task very easy.

I will say that if you're interested in using the same quaternion to rotate multiple vectors — as opposed to using different quaternions for each rotation — it's most efficient to convert the quaternion to a rotation matrix (using quaternion.as_rotation_matrix), and then use numpy.

But achieving my original objective is proving more difficult than I had hoped. I'll keep this thread posted with any developments.

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

3 participants