Skip to main content

Timeline for Direction vector to quaternion

Current License: CC BY-SA 3.0

10 events
when toggle format what by license comment
Oct 2, 2017 at 22:07 history edited Bram CC BY-SA 3.0
fix order
Oct 2, 2017 at 18:06 vote accept Avi
Oct 2, 2017 at 18:06 comment added Avi @Bram that did it, angle should be angle = atan2( vector.x, vector.z) ... thank you very much, this is a beautiful whole answer!
Oct 1, 2017 at 23:44 comment added Bram @Avithohol atan2() and atan2f() are in libc's math.h header. Note that you cannot use atan() as that takes 1 parm, not two. If the angle is 90° off, try reversing order: atan2( vector.x, vector.z ) to see if that is better.
Oct 1, 2017 at 20:02 comment added Avi @Bram One note: seems to work with atan as i don't find atan2 ... is it expected? as I see GLM keeps atan2 for compatibility only, and runs atan under the hood ...
Oct 1, 2017 at 19:48 comment added Avi @Bram thanks, it works and much shorter than my matrix solution ... one minor thing: if i rotate a model with the resulting quaternion, it seems to always add extra 90 to the correct rotation... my model is originally facing +Z axis ... but i can fix that substracting a constant -90 degree
Oct 1, 2017 at 10:35 comment added DMGregory By using the half-angle trig identities I mention in the second half of my comment. eg. cos(a/2) = sqrt((1 + cos(a))/2) for angles in the range (-π...+π) — still need two square roots instead of two trig and one inverse trig, so it's not a gigantic savings by any means, it's just kind if a cute pattern. ;)
Oct 1, 2017 at 3:31 comment added Bram If you know cos(a), how does that help you to know cos(a/2) then, without doing cos( acos(a) / 2 ) which seems costly, and also would require unit vector.
Sep 30, 2017 at 23:29 comment added DMGregory We can do one better and skip computing the angle directly, by noting that x & z already encode the sine and cosines we need to use the half-angle trig identities...
Sep 30, 2017 at 22:14 history answered Bram CC BY-SA 3.0