TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Rotations with quaternions

207 pointsby imadralmost 4 years ago

23 comments

gspralmost 4 years ago
The reason this works is often skipped in computationally oriented writeups:<p>Rotations of 3-dimensional real space form the topological group SO(3). Naive parameterizations of that group do not form a cover [1], but the group of norm-1 quaterinons, Spin(3), does.<p>The failure of naive parameterizations, like the Euler angles, to be a cover manifests itself as gimbal lock.<p>[1] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Covering_space" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Covering_space</a>
评论 #27354004 未加载
评论 #27355053 未加载
评论 #27353843 未加载
评论 #27354055 未加载
评论 #27354167 未加载
评论 #27359716 未加载
评论 #27366812 未加载
评论 #27355048 未加载
OmarShehataalmost 4 years ago
This article incorrectly states that gimbal lock is a property of Euler angles, and that using quaternions prevents it.<p>This is a common misconception.<p>Euler angles can be used to rotate an object exactly the same way as quaternions do with no gimbal lock. Similarly, you can apply quaternions in such a way that gimbal lock will happen (if you wanted to represent a physical system of gimbals with quaternions, where that is a physical property).<p>I wrote a short article demonstrating and clarifying this, hope it helps: <a href="https:&#x2F;&#x2F;omar-shehata.medium.com&#x2F;how-to-fix-gimbal-lock-in-n-dimensions-f2f7baec2b5e" rel="nofollow">https:&#x2F;&#x2F;omar-shehata.medium.com&#x2F;how-to-fix-gimbal-lock-in-n-...</a>
评论 #27356342 未加载
评论 #27355747 未加载
评论 #27356911 未加载
评论 #27357080 未加载
评论 #27355453 未加载
评论 #27355579 未加载
评论 #27358402 未加载
评论 #27355444 未加载
评论 #27356055 未加载
aardvark179almost 4 years ago
Since this will get posted here anyway I’ll just get it done now. <a href="https:&#x2F;&#x2F;marctenbosch.com&#x2F;quaternions&#x2F;" rel="nofollow">https:&#x2F;&#x2F;marctenbosch.com&#x2F;quaternions&#x2F;</a><p>I don’t entirely agree with the article’s viewpoint that people do not perfectly understand quaternions and therefore they should not be used, as I get the feeling there are many parts of 3D graphics that are not perfectly understood by developers, and that’s okay.
评论 #27358300 未加载
greggman3almost 4 years ago
Be aware, quaternions are not always the right solution. There&#x27;s a reason Unity, Unreal, 3DSMax, Maya, Blender, etc all support Euler interpolation in animation. A simple example is an artist might want to show a clock hand spinning fast to show the progress of time. To do that they set a start angle of 0 and an end angle of say 20000. Sure, there may be ways to represent that with specialized quaternions but in general the 3D tools all seems to default to using Eulers.<p>This is an issue with the GLTF format. They chose quaternions to represent rotations in animation and as such can&#x27;t easily represent what the artist&#x27;s intent was.<p>You might claim you can sample the Euler animation and split it into multiple quaternion slerps but that brings up another issue which is you need support for discontinuous animations in order to handle other situations (another thing the GLTF format apparently didn&#x27;t consider).
评论 #27359492 未加载
评论 #27359342 未加载
评论 #27359205 未加载
vladTheInhaleralmost 4 years ago
For anyone who is interested in an accessible introduction to representing rotations, I highly recommend this site: <a href="https:&#x2F;&#x2F;rotations.berkeley.edu" rel="nofollow">https:&#x2F;&#x2F;rotations.berkeley.edu</a>. One of my professors provided it for one of his courses, and it&#x27;s been a really helpful reference several times since then.
评论 #27363273 未加载
评论 #27358275 未加载
imadralmost 4 years ago
I made this guide on how to implement quaternions yourself and use them to rotate objects in a 3D engine. The implementation is probably not the most efficient, but I tried to make it simple enough to understand how quaternions work.
评论 #27353785 未加载
Jyaifalmost 4 years ago
Most of the time you don&#x27;t want to use his SLERP function. You can even see what is wrong in his illustration video: the cube does 3&#x2F;4s of a full rotation, while only 1&#x2F;4 of a full rotation would have been sufficient. In other words, it&#x27;s not always taking the shortest path between 2 rotations.<p>If you are not careful, this is what you may end up with: <a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;FIFA&#x2F;comments&#x2F;9gms3n&#x2F;most_realistic_graphics_ever_in_fifa_history&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;FIFA&#x2F;comments&#x2F;9gms3n&#x2F;most_realistic...</a>
评论 #27355353 未加载
FabHKalmost 4 years ago
A few remarks:<p>0) Very nice practical introduction to quaternions and their application to rotation.<p>1) Neat didactic &quot;textbook&quot; implementation, but note that it is not production quality (eg potential overflow in the norm function unnecessarily). That was not the aim, either, but just something to bear in mind.<p>2) As a supplement, a useful practical reference for rotations in 3D (with good clarifications and basically all formulae you&#x27;ll ever need, but no implementation) is<p><i>Representing Attitude: Euler Angles, Unit Quaternions, and Rotation Vectors</i> by James Diebel<p><a href="https:&#x2F;&#x2F;www.astro.rug.nl&#x2F;software&#x2F;kapteyn-beta&#x2F;_downloads&#x2F;attitude.pdf" rel="nofollow">https:&#x2F;&#x2F;www.astro.rug.nl&#x2F;software&#x2F;kapteyn-beta&#x2F;_downloads&#x2F;at...</a>
评论 #27354070 未加载
rthomas6almost 4 years ago
As a non-math person, I&#x27;ve thought a lot about quaternions and why they need 4 dimensions, and why there aren&#x27;t 3d complex numbers. It&#x27;s because if you think about it, on the complex plane, the imaginary number i just represents a rotation of 90 degrees. Now if you think about a 3d space, i represents a rotation across one dimension, and j represents a rotation across another dimension. But how do you rotate from i to j? You can&#x27;t without another number k.
评论 #27357856 未加载
unholinessalmost 4 years ago
If you want to intuitively understand <i>why</i> this particular 4D construction is the right representation of a 3D rotation, then I highly recommend 3blue1brown&#x27;s explorable interactive video series on the topic:<p><a href="https:&#x2F;&#x2F;eater.net&#x2F;quaternions" rel="nofollow">https:&#x2F;&#x2F;eater.net&#x2F;quaternions</a><p>The interactive videos alone are quite the technical feat, but after going through it, it&#x27;s honestly hard to imagine fully understanding this topic with less technology (or with a less incredible teacher!)
评论 #27361732 未加载
rdevsrexalmost 4 years ago
There was a post about Geometric Algebra, a while back. Is that more in use these days?
评论 #27362289 未加载
评论 #27360206 未加载
Scene_Cast2almost 4 years ago
As a much more intuitive version of quaternions, there&#x27;s Geometric Algebra (aka Clifford Algebra). In 4D, the calculations end up being the same, but there&#x27;s much more intuition and generalizability behind the Geometric version.
darkstarsysalmost 4 years ago
This is good, thanks. But a much more interesting problem I haven&#x27;t seen a good writeup for is how to interpolate smoothly between quaternions at different times. Quaternion slerp has jerks (C_0 but not C_1 or C_2) at the keyframes.
评论 #27355246 未加载
评论 #27384532 未加载
评论 #27357857 未加载
评论 #27354991 未加载
sojuz151almost 4 years ago
Small trivia: Existence of two unit quaternions corresponding to the same rotation is the same thing as the fact that an electron must be fully rotated twice before it has the same configuration as when it started.
评论 #27365809 未加载
评论 #27359444 未加载
ww520almost 4 years ago
Quaternion is great for dealing with 3D rotation. Another great approach is using the rotor in geometric algebra. It&#x27;s pretty simple and it works on rotation in dimensions higher than 3D as well.
mwkaufmaalmost 4 years ago
These implementations of difference and slerp aren&#x27;t accounting for geometric double-cover. You want to do a dot-product check first to make sure you&#x27;re in the same &quot;hemisphere&quot;
gabereiseralmost 4 years ago
I love this. Quaternions were my nemesis while learning 3D math. I think it was the way I was taught it but quaternions always confused me as I mixed them up with euler angles. Having resources like this that explain them in detail really helps grok what quaternions are, can do, and how to incorporate them in your project. Great job! I’m over the hump now. I use dual quaternions for skinning and single q’s for rotation storage (why store 3x3m when a 4f quaternion will do?).
Animatsalmost 4 years ago
For a simpler discussion, see [1].<p>[1] <a href="http:&#x2F;&#x2F;wiki.secondlife.com&#x2F;wiki&#x2F;Rotation" rel="nofollow">http:&#x2F;&#x2F;wiki.secondlife.com&#x2F;wiki&#x2F;Rotation</a>
captainmuonalmost 4 years ago
&gt; A quaternion is basically a 4 dimensional vector, so it has a magnitude (or norm, or length)<p>Is it really a <i>vector</i> in the physical sense? People often say vector when they mean N-tuple -- for example we learned in high school that vectors are just N numbers taken together.<p>For physicists, a vector must satisfy certain transformation laws - it must transform in the correct way if a rotation is applied, and the scalar product must be invariant of the coordinate system, IIRC. I don&#x27;t have enough intuition of quaternions to say how they behave under transformations, though. I would be surprized if you could have &quot;proper&quot; vectors with four components in three-dimensional space.
评论 #27360108 未加载
评论 #27359421 未加载
frankusalmost 4 years ago
Sort of unrelated but I wonder if this could make certain kinds of latitude&#x2F;longitude calculations easier.
评论 #27354561 未加载
marcodiegoalmost 4 years ago
tldr: Simply explained without demonstrations: Quaternions are hypercomplex numbers of the form<p>w + x<i>i + y</i>j + z<i>k<p>Where w, x, y, and z are real and i^2 = j^2 = k^2 = -1 and i</i>j = k, j<i>i = -k, j</i>k = i, k<i>j = -i, k</i>i = j, i<i>k = -j.<p>Being u = (x, y, z) = x</i>i + y<i>j + z</i>k a unitary vector parallel to a rotation axis, it is possible rotate any vector q with a theta arc around u by doing:<p>p<i>q</i>p&#x27;<p>where p = cos(theta&#x2F;2) + sin(theta&#x2F;2)<i>u and p&#x27; = cos(theta&#x2F;2) - sin(theta&#x2F;2)</i>u .
dnauticsalmost 4 years ago
am I wrong that this use of a union is UB in C?
评论 #27355482 未加载
neonologicalalmost 4 years ago
Guys I work at a company that uses Quaternions for rotations of physical objects. PTUs we call them (Pan Tilt Units).<p>I am telling you Quaternions have HUGE issues. These issues become much more apparent when you deal with physical objects.<p>Here&#x27;s the thing Quaternions don&#x27;t exist in reality. It represents an orientation of rotation but it completely masks the path took to achieve that orientation.<p>For every gimbal in reality there is an actual YawPitchRoll (YPR) that was executed to achieve that orientation. AS soon as you convert that real YPR into a Quaternion you lose the YPR that was needed to achieve that orienation.<p>So let&#x27;s say I need to have one gimbal imitate the position of another gimbal. I take the YPR given to me by gimbal &quot;A&quot; convert the YPR to a Quat, send that Quat over the wire to Gimbal &quot;B&quot; and convert that Quat back to YPR to feed to the gimbal so it can rotate itself to imitate the orientation of gimbal A.<p>The quat is a higher entropy form of information. Now when converting back to YPR there are MULTIPLE YPRs that yield the same orientation. You can derive a YPR that is out of bounds of the physical gimbal.<p>Literally you can get a YPR that tells your gimbal to Yaw 190 and pitch all the way back past 90 to 170 degrees and roll 180 degrees until it&#x27;s right side up. This YPR is identical to a yaw of 10, a pitch of 20 and 0 roll. Quaternions hide the original YPR, you lose information so when you receive a Quaternion it&#x27;s hard to translate it into a physical realization of the orientation.<p>The company I work for doesn&#x27;t realize this. They used Quaternions from day one and we have all kinds of headaches like this when we try to extract the YPR and use these orientations in the real world. Actually I should say only I have these headaches. A lot of people haven&#x27;t figured out this problem yet.<p>The only time you should use Quats are if you need to transform an orientation or you&#x27;re dealing with virtual objects that have no rotational limits. Everybody thinks quats are magic and better. They are not. They have huge downsides. Huge.
评论 #27374064 未加载
评论 #27361255 未加载
评论 #27362204 未加载
评论 #27360478 未加载