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

changing the element of a quaternion #38

Closed
calocedrus opened this issue Mar 10, 2017 · 1 comment
Closed

changing the element of a quaternion #38

calocedrus opened this issue Mar 10, 2017 · 1 comment

Comments

@calocedrus
Copy link

Say I have:
myq = np.quaternion(ww,xx,yy,zz)
I can do

myq_x=myq.x # a float
myq_y=myq.y # a float

but not
myq.x = myq.y # AttributeError: readonly attribute
I would find it useful to be able to have the quaternion attributes as write also, for example to easily change the axis of rotation. What is the reason to set them as readonly? And then how to, for example, swap 2 elements of a quaternion (such as swap xx with yy as above)?

@moble
Copy link
Owner

moble commented Mar 10, 2017

That's a great question! The "reason" they were set as READONLY is because I'm no expert on python's C API, so I just didn't know any better. I've changed that now, though, so if you update you should be able to set those components. Thanks!

The usual python way to swap a and b is to do a, b = b, a. So in this case, you can do

import numpy as np
import quaternion
q = np.quaternion(0, 1, 2, 3)
q.w, q.x = q.x, q.w

@moble moble closed this as completed Mar 10, 2017
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