Re: [Algorithms] Zeroing a quaternion rotation axis
Brought to you by:
vexxed72
From: Jonathan B. <jo...@nu...> - 2004-04-19 16:59:22
|
Matt wrote: > In which case you can encode the yaw and pitch directly as euler angles; > there is a definite order of operations here. Actually this is one thing I want to hammer that, now that you say this, I don't think I made clear enough in my earlier replies. Back when I was newer at 3D programming, and not so good at dealing with rotations (and transforms in general), I used to always think about rotation problems as having this order of operations. Let's go so much in this direction, *and then* so much in that direction, and we get our answer. Well, this becomes very difficult to think about for that basic reason that rotations don't commute, that your unit vectors like to move curvily around the sphere. I always found myself bogged down first of all in confusions about trying to visualize what the order of operations really should be, and then second of all in actually trying to visualize that order being carried out, to verify that it was really doing what I wanted. And when it didn't work -- which was very often -- it was easier to just try juggling around the orders of things in the code until it worked (much like juggling minus signs around in some equation til it works), rather than sit down and really understand what was going on. Because it was so hard to visualize. Of course this led to really sloppy code that happened to work at the moment, but I knew if I tried to play with it much it would break. These days I feel I am a lot better at dealing with rotations, and there's a large class of problems I can just solve without really thinking about them, that as recently as a few years ago would have been very troublesome. One of the main differences between then and now is that now I usually don't visualize rotations in terms of some operations that must happen in a specific order (*usually*, and I'll talk about the exception in a minute). I just think about What The Answer Is, phrased in a way that is entirely non-temporal, and then come up with some steps to compute it that are also non-temporal. So note that in my previous email when I expressed the solution to the problem, I didn't say "rotate around this axis by so much, then around this other axis by so much". Instead I said, "there exists this vector at these angles, and this other vector at this other angle". Because it is non-temporal, the "there exists X" form of answer does not rely on visualizing the results of subsequent rotations, which means the non-commutativity problem, and the difficulty-of-visualization problem, just don't come into play. You just know the answer. That suits me for most problems. I said there was one way in which I think about rotation sometimes as happening in ordered stages, and that is when I use the reach/twist formulation. This happens in two explicit steps -- first you reach, then you twist. But it's still easy to visualize because the two steps do not have any dependencies between each other. In fact the first step isn't even really a rotation -- you only care about the forward vector. You say, "point the forward vector in the direction of the target, but I don't really care what happens to the other two axes". This is the "reach" part. After that is done, you perform the "twist" part, which says: "spin the other two axes around the forward vector until they end up in the right directions". This second phase does not change the forward-vector, so there is no real dependency between it and the first phase. Because there are no dependencies, that whole rotations-act-funny-so-they-are-hard-to-visualize thing just doesn't come into play. Leveraging just these two methods ("There exists X" and "reach/twist"), I easily solve any basic rotation problem that I encounter in making games. The only things that remain are the non-basic problems where for some reason you really have two arbitrary rotations that get concatenated and you really want to visualize the result. Which happens very rarely. At that point you just want to switch to algebra, multiply the quaternions together and see how it comes out and what that means to you. -Jonathan. |