6 ms·
Exponentially Better Rotations (2022)
- jiyinyiyong 2y agoanother way to understand 3D rotation is using geometric algebra, which regard a 3D rotation with 2 reflections within an angle in the reflection planes. It's very interesting and also available calculating with 3D vectors. https://marctenbosch.com/quaternions/#h_5 https://marctenbosch.com/quaternions/#h_5 https://www.bilibili.com/video/BV1Ey4y1P782/?vd_source=856977e0dfd83a275bdad8d030c9115d https://www.bilibili.com/video/BV1Ey4y1P782/?vd_source=85697...
- tmiku 2y agoI've had a long work week and it's almost over and using the sliders to rotate this cow is exactly what I needed. I feel serene. Thank you.
- normcoreashore 2y agoLol yeah same. Glossed right over that wall of numbers
- romwell 2y agoThen you may like playing with this too (if you're on the desktop): Press 1-6 on the keyboard for cubes to go all spinny https://romankogan.net/math/arcball_js/index.html https://romankogan.net/math/arcball_js/index.html
- totetsu 2y agoI feel a low effort ios cashcow game is begging to be made
- banku_brougham 2y agoSlidy-Cow
- chaboud 2y agoCow Tau: Emperor bull requires that you properly orient all of the cows using axis angle interpolation, but over-spinning will churn their milk into butter.
- beardbandit 2y agoI can't describe how fast my eyes glazed over seeing all those numbers. The cow was very cute.
- GreedCtrl 2y agoThis is awesome. I was looking for a solution for averaging multiple rotations, and I found https://mathweb.ucsd.edu/~sbuss/ResearchWeb/spheremean/paper.pdf https://mathweb.ucsd.edu/~sbuss/ResearchWeb/spheremean/paper... This method looks a lot easier than that paper, at least at my level of math.
- romwell 2y agoWhat's your context for averaging multiple rotations? Averages are something that you can do with sums, where order of composition doesn't matter. Rotations don't commute, so the concept of average as we understand it doesn't normally apply to them. If you're holding a phone: rotate the screen away from you 180° (so you'd be seeing the back), then clockwise 90° relative to the ground (around vertical axis). Your camera will be facing your left. Now hold the phone normally, and do the same rotations in the opposite order. Your camera will now be facing your right. Question: where should the camera be facing in the "average" of these two rotations? There's no single answer — it depends on what you need from the average.
- stirfish 2y agoMaybe it's Friday and my brain is cooked, but my camera keeps facing left in both cases.
- jonlong 2y agoIf you start with the phone upright and rotate the screen away from you by turning the phone around the vertical axis, then both rotations are around the same axis and of course they do commute. My guess is that romwell is holding the phone flat, so that the rotation away from you is about a horizontal axis; then you should experience the noncommutativity. (The resulting orientations are 180 degrees apart, which indeed makes it difficult to say that any one orientation should be the unique average. But this is due to the geodesic structure of the space of rotations, not the noncommutative product that happened to construct these points, see above.)
- crote 2y ago
- nine_k 2y agoThis is great. (Not only the cow part.). What I additionally appreciated is the fact that the methods end up computing a standard rotation matrix. If you need to rotate a million vectors, all you need to do is to apply these interesting calculations once, and then run your highly optimized matrix multiplication pipeline.
- deleted 2y ago[deleted]
- romwell 2y agoThis talks about one of my pet peeves with a lot of 3D software: they don't use Arcball[1] interface for rotation. Autodesk products do (3DSmax, Maya), but Blender and OpenSCAD don't. And when I worked at Roblox, I couldn't convince the PM to let me implement it, because the users got by with whatever was there — and if they wanted more, they could use something else (...which they did, and Roblox stock reflected that in 2022). Arcball is based on quaternions[2] (using exp for interpolation). It's the only interface with these properties: 1. Any rotation can be accomplished with a single drag 2. No gimbal locks 3. Tracing a closed loop with a sequence of drags results in coming back to where you started Once you formalize this, you can prove it mathematically (ultimately, this comes from unit quaternions giving a 2-cover of SO(3) in the same way unit complex numbers giving exactly the rotations of a circle). For anyone interested, here is my reference implementation of Quaternions / Arcball that you can play with on the page: https://romankogan.net/math/arcball_js/index.html https://romankogan.net/math/arcball_js/index.html The code is very-commented Java (Processing library, running in JavaScript by the magic of ProcessingJS). It's one way you can feel the fancy math. Your hands and body will understand quaternions before your brain does. If you ever work on 3D software, please use this, and thanks in advance <3 [1] Arcball: http://courses.cms.caltech.edu/cs171/assignments/hw3/hw3-notes/notes-hw3.html http://courses.cms.caltech.edu/cs171/assignments/hw3/hw3-not... [2] Quaternions for rotations: https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotati... [3] Arcball in Processing: https://romankogan.net/math/arcball_js/index.html https://romankogan.net/math/arcball_js/index.html
- Nathanba 2y agowhy does it feel so much worse when you don't drag from the middle and instead from the e.g right side? It feels stuck and sometimes it snaps. If the point from which rotations are calculated changes then I think it should somehow be visually obvious what this means for the rotation and be shown on the screen
- romwell 2y agoThanks for the feedback! Imagine you're spinning a globe with your finger. Obviously not much would happen if you poked outside the globe. And while your finger is on the globe, you can't point at the sky (unless you finger is, well, stuck to the globe while you're rotating it - pointing to the sky would let go of the globe). This is what you're doing here, and absolutely, I should add a visual representation for the globe and where you're poking it when you hold the mouse button down. You feel "stuck" when the cursor attempts to leave the globe. And moving the cursor around that boundary is how you rotate around the axis facing poking from the screen. This behavior can be changed/customized to an extent, I picked what felt good to me here.
- 6gvONxR4sf7o 2y agoThe lie group/lie algebra correspondence is one of the coolest things i wish i’d been taught in school. It’s the exponential and log map in the article, but in a super reusable setting. You take some totally abstract thing you want to work with[0], say 3D rotations, but totally avoiding any details of specific coordinates that might get you into trouble. That’s the lie group. Then you can derive representations of it in coordinates that behave nicely. This is called the corresponding lie algebra. Then for free you get a way to go back and forth between the coordinates and the abstract thing[1], and ways to compose them and stuff. Turns out that this is the exponential map and the log map talked about in the article. What’s even cooler is that you can then compose them on either side, the abstract side or the coordinate side in a way that plays nicely. You get interpolation and averaging and all that in a fairly sensible way too in most cases you’ll deal with as an engineer. And best of all, when you can phrase your problem as a combination of lie groups, you can just google for what their algebras are and get lots of work for free that would be tons of time to do yourself. [0] the thing has to be something with a notion of smooth change, plus a bit more structure it probably has. [1] going back and forth has some ‘connected components’ issues sometimes, but that’s just another reason it’s great to piggyback on known results.
- wyager 2y ago> unit quaternions also don’t form a vector space Unit quaternions are the lie group. If you want something you can add willy-nilly, you want the lie algebra of all quaternions, which represent rotational velocities, just as axis-angle represents rotational velocities. Comparing unit quaternions to axis-angle is a bit of a category error - it would be more appropriate to compare unit quaternions to rotation matrices, and all quaternions to axis-angle. > One advantage of using quaternions is how easy the exponential map is to compute—if you don’t need a rotation matrix, it’s a good option. You rarely need a rotation matrix at all when using quaternions. As mentioned in the article, you can compute rotations using `pqp^-1`. I think the easiest way to understand quaternions is just to read about geometric algebra. It took hundreds of years to invent quaternions, but once you understand geometric algebra (which is shockingly simple), you can invent quaternions in just a few minutes. I found this article to be a good intro several years ago: https://crypto.stanford.edu/~blynn/haskell/ga.html https://crypto.stanford.edu/~blynn/haskell/ga.html
- blt 2y agoWhen you say "all quaternions" did you mean "pure imaginary quaternions"?
- wyager 2y agoOops, yes I did. For curious readers: `2` is a quaternion, but `exp(2)` doesn't generate a rotation, it generates 7.389... just like normal exponentiation on reals. So if you have a real term in your lie algebra, it will generate things that scale the object as well as rotating it. So instead you want only `ai + bj + ck`, as `exp(ai + bj + ck)` will always have magnitude 1
- cyber_kinetist 2y agoI think the exponential map is still the most robust way to think about rotations, since it gives you tools to deal with the Lie group of SO(3) in the most straightforward way (switching between coordinates, dealing with differentiation and tangent spaces, etc.) Even when going through all the formulations with geometric algebra, you still land on using rotors (isomorphic to quaternions) and motors (isomorphic to dual quaternions) to represent SO(3) / SE(3) spaces - but I think for that purpose 3x3 rotation matrices / 4x4 transformation matrices with exponential maps are still much more useful. (Quaternions do have an advantage that it stores up less space and also faster to multiply with each other - but when you want to transform points with it then matrices are still faster. In overall in terms of efficiency it really depends on the situation.)
- deutschepost 2y agoOne of the coolest things I learned in university was that you can just put rotation matrices inside the state of a Kalman filter if you just override the + operator to take a matrix and a change in vector space and the — operator to take two matrices. This allows you to estimate rotations without the fear of gimbal lock. https://openslam-org.github.io/MTK https://openslam-org.github.io/MTK
- heavenlyblue 2y agoLooks like gibberish advertising for the project
- deutschepost 2y agoIt’s pretty hard to explain in short. But estimation algorithms don’t work on angles for example. For an algorithm an angle is just a number. So the difference between 359 and 1 degree looks pretty big. It is also not possible to just put a rotation matrix inside a state, because the algorithm has no concept of orthonormality. But if you define the change of a state in terms of vectors and the state itself as a rotation matrix you can just use off the shelf estimation algorithms like least squares and Kalman filters. You just need to redefine the plus and minus operators. Which is nothing you need a project for. You can just do it yourself.
- KeplerBoy 2y agoThen you have some reading to do. Sometimes technobabble is appropriate.
- roger_ 2y agoDo you mean the tangent space of SO(2) as a state?
- deutschepost 2y agoFor simple angles you can use an element of SO(2) as your state. But if the algorithm calls for a difference of two states, the result would have to be an element of a real vector space (in this case a single number between -pi and pi). Analogue to this an addition of a state manifold and a vector also results in a state manifold. You can switch between those representations using the exp and log functions. In the papers these „new“ operators are described as boxplus and boxminus. And the elegant thing of this approach is that in most cases you just would replace plus with boxplus and minus with boxminus and it just works(tm)
- vendiddy 2y agoIt took me a long time to realize that, in the field of math, people come up with abstractions in the same way you might think of an abstraction in software engineering. I was confused as a kid. Why create imaginary numbers? What is the point of matrixes? It wasn't until later I realized that these representations were designed. If you make up this thing called an imaginary number, these calculations become easier. If you write linear equations like a matrix, it's a lot easier to reason about than writing out the full thing. It sounds obvious but nobody ever told me this! Just me?
- ndriscoll 2y agoThis continues to be true when you study more abstract math. e.g. "group" is an interface, and "a group" is any type with an operation that implements the 3 required properties/methods. Likewise with vector space, ring, metric space, category, etc. Math is full of interfaces as a "design pattern". (Interfaces in math are more like type classes and not inheritance in programming. e.g. the same set/type can be a group in more than one way.)
- delta_p_delta_x 2y agoAwesome blog. Then I clicked on the author's profile, read another of their posts, and saw: > I first encountered programming sometime around 2010, when I was 9 years old. I was 13 in 2010, and trying to stuff secondary school maths and science into my head. Every time I see a cool computer graphics-related blog post, it's by someone younger and way more talented than me. I feel extremely inadequate; my inner voice immediately went to something I can't really publicly say in case I get a dozen help-lines in response.
- anonymoushn 2y agoIt's not over for you, I self-taught some niche skills in the last couple years that some bigco apparently wants to pay for. I'm 35ish. Of course, I don't have any advice about how to do this, because I did it by really liking the thing and doing it all the time. But presumably some sort of structured practice would work too.
- Certhas 2y agoI don't get the love of quaternions in this context. How are quaternions more intuitive than matrices? A matrix acts on a vector. Rotations act on vectors. What could be more natural than to look at rotations as matrices? The matrix exponential then makes all this intuitive to work with, if you connect it to solutions of ODEs: dx/dt = Ax has solution exp(t A). If A is skew symmetric, then the change in x is orthogonal to x at all times. So it's a rotation that doesn't change the length. (Alternative: apply a small orthogonal change over and over: (1 + delta A)^N x) Lie Groups/Algebras vastly generalize this, and you can call skew symmetric matrices geometric algebra, but that's not important. Important is that you generate rotations by continuously making orthogonal changes, and that the exponential map describes this process. I find this picture far more geometric and intuitive than anything else.
- setopt 2y agoMight be worth pointing out that quaternions themselves are often represented as matrices as well: That’s the Pauli matrices, widely used to model quantum spin. One advantage of quaternions is that it’s (IMO) easier to calculate things with them using only pen and paper than it is to do equivalent matrix multiplications by hand. Personally I find them “intuitive” in the same sense as complex numbers are intuitive: They seemed weird on first exposure, but they now feel simpler to use and reason about than the alternatives I know.
- adgjlsfhk1 2y agoOne advantage of quaternians from a computational perspective is that they are 4 numbers vs 9 for a 3x3 matrix (and applying the rotations has a similar reduction in flops)
- dahart 2y agoThe article explained a major advantage of quaternions over matrices. Quaternions interpolate well and matrices don’t. This property is very important for animation and other things in computer graphics, like computing frames along a 3d spline curve.
- blt 2y ago
- deleted 2y ago[deleted]