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

Return quaternion as [x,y,z,w] #29

Closed
pozdnyakov opened this issue Apr 7, 2017 · 12 comments · Fixed by #30
Closed

Return quaternion as [x,y,z,w] #29

pozdnyakov opened this issue Apr 7, 2017 · 12 comments · Fixed by #30

Comments

@pozdnyakov
Copy link

Even though a standard form of quaternion representation in math is starting from the real part (i.e. [w,x,y,z]) many of popular WebGL frameworks [1][2][3][4] use a different order of [x,y,z,w]. We probably should be compatible and should update the spec accordingly.

[1] https://doc.babylonjs.com/classes/2.4/quaternion
[2] https://threejs.org/docs/api/math/Quaternion.html
[3] https://www.blend4web.com/api_doc/module-quat.html#.fromValues
[4] http://developer.playcanvas.com/en/api/pc.Quat.html

@pozdnyakov
Copy link
Author

@alexshalamov @anssiko @kenchris thoughts?

@alexshalamov
Copy link

sounds like a good idea.

pozdnyakov pushed a commit to pozdnyakov/orientation-sensor that referenced this issue Apr 7, 2017
@kenchris
Copy link
Contributor

kenchris commented Apr 7, 2017

I think it makes a lot of sense. Also in math quaternions are normally represented using i, j and k components, so order doesn't matter, in mathematical sense. If we define just the values (ie no i, j and k), ie. x + yi +zj + wk, the order [x, y, z, w] makes a lot of sense.

The following are valid quaternions:

1
14
312 + 7i (a quaternion and a complex number!)
-1 + 4i - 8j + 8k

Like complex numbers they i^2 == -1 :-) and so it j^2 == -1 and k^== -1 and ijk == -1

@pozdnyakov
Copy link
Author

in each of your examples the real component stays first and that's the standard representation :)

@kenchris
Copy link
Contributor

kenchris commented Apr 7, 2017

Yes, I assume that x is used for representing the real component, right?

@pozdnyakov
Copy link
Author

pozdnyakov commented Apr 7, 2017

no, w is real, it's equal to cos(theta/2)

@kenchris
Copy link
Contributor

kenchris commented Apr 7, 2017

Oh, not obvious :-) so is that also the case for the other implementations?

Maybe we should add a note explaining this

I guess it makes sense when you talk about scalar and vector part. But this definitely needs a note and we need to make sure that w is really the scalar part in the other APIs

@pozdnyakov
Copy link
Author

For both math and alphabetical reasons the current order [w,x,y,z] is correct, however for some reason JS frameworks prefer [x,y,z,w] , so this issue is more about API convenience..

@pozdnyakov
Copy link
Author

Maybe we should add a note explaining this

Could you give more details, what such note should contain?

@kenchris
Copy link
Contributor

kenchris commented Apr 7, 2017

Sure, say how quaternions are represented, ie w + xi + yj + zk, with a scalar w and a vector x, y, z. And then mention that we expose these as vector + scalar, [x, y, z, w] as that is the most prevalent way of doing that when exposed as an array, but that other libraries etc could impose a different order like [w, x, y, z]

@pozdnyakov pozdnyakov reopened this Apr 10, 2017
@pozdnyakov
Copy link
Author

Reopen to add an explaining note

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

Successfully merging a pull request may close this issue.

3 participants