Implementing a formula with quaternions - Printable Version +- iDevGames Forums ( http://www.idevgames.com/forums)+-- Forum: Development Zone ( /forum-3.html)+--- Forum: Graphics & Audio Programming ( /forum-9.html)+--- Thread: Implementing a formula with quaternions ( /thread-3820.html) |

Implementing a formula with quaternions - akb825 - Oct 12, 2006 05:59 PM
I haven't had any replies with my previous thread, so perhaps I will now that I can be more specific. I am trying to implement a formula with quaternions to find the acceleration to get to a certain place at a certain time, accelerating for a certain percentage of that time. I have 2 times, t1 and t2, where t1 + t2 = t. (essentially, the time that it's accelerating and the time that it's "coasting" through with the current velocity) With the initial velocity, vi, and the final velocity, vf, and the distances d1 and d2 (which add up to the total d), I have the following relations: vf = vi + a*t1 d1 = vi*t1 + 1/2*a*t1^2 d2 = vf*t2 After substituting, I derived the final formula for the acceleration: a = (d - vi*t)/(t1*t - 1/2t1^2) After testing the formula out in some simple situations, I'm pretty confident it's correct. The problem now, though, is getting it to work with quaternions. I resolve scalar multiplies by scaling the angle, and vector additions/subtractions with quaternion multiplications/conjugate multiplications. (I also try to make sure the ordering makes sense, but I can't be guaranteed with all of it) I already know my formulas for applying acceleration and velocity work. I also have a simple animation type that just uses a velocity without acceleration that works. However, something is wrong with the use of this formula. To find d, I multiply target rotation by the conjugate of the current rotation. That part I know works, since it works with the simple velocity case. However, finding the acceleration has been problematic. I've tried everything I can think of: multiplying the conjugate of vi scaled by t and d, switching the 2, scaling each individually by the denominator and switching around the orders of the latter case. It works when vi is the identity quaternion, but doesn't otherwise. Can anybody shed some light on this situation? Perhaps there is a trick I'm missing, or something else I have to multiply with? (that doesn't affect vi when it's the identity) Implementing a formula with quaternions - akb825 - Oct 13, 2006 12:20 AM
I think I see my problem: this problem essentially consists of 2 parts: the part for d1, and the part for d2. In order to solve for a, I had to combine those parts and shuffle their constituents together, which is incompatible with the non-communitive aspects of quaternions. After fiddling around with the equations, I couldn't find any way to resolve it without preserving the absolute order. It looks like I'm going to have to try another set of equations to do the same thing. (unless, of course, any of you are able to find a solution, which I would be very happy to happen; I'm not holding my breath on the possibility, though. ) Implementing a formula with quaternions - akb825 - Oct 13, 2006 10:33 PM
I tried to use Newton's Method with vi*t1 + 1/2*a*t1^2 + vi*t2 + a*t1*t2 - d (aka: d1 + d2 - d) to solve for a, but with keeping the order the same. Unfortunately, I get the same result. Does anybody here know anything on this subject? Or will I need to continue monologging? The lack of information anywhere on this subject is really holding me back. Implementing a formula with quaternions - unknown - Oct 13, 2006 11:56 PM
There is a massive amount of information about quaternions, its just mostly pretty much useless.. All I can recommend is you read and understand this, http://www.geometrictools.com/Documentation/Quaternions.pdf Implementing a formula with quaternions - akb825 - Oct 14, 2006 01:34 AM
Thanks for the link. Looking at the derivative function, I think I'll try Newton's method again, but when taking the derivative I won't assume that it reaches 1 when it's just to the power of 1. Hopefully this will work, because I would hate to go through all this work and only have linear animations working. Edit: why does every place use a different slash for that smilie? Implementing a formula with quaternions - aarku - Oct 14, 2006 03:32 AM
Is the end goal just to interpolate between quaternions in different ways? Ease in, Ease out, Ease in and out..? That type of thing? If you can linearly or spherically interpolate, you're 99.9% of the way there, then. -Jon Implementing a formula with quaternions - akb825 - Oct 14, 2006 10:22 AM
It's more than just interpolating between quaternions smoothly. I want it so no matter the current velocity or position of the bone, it can smoothly go to the next one smoothly. That way, if it's currently moving and you suddenly put in another animation, it accelerates out of its current velocity instead of suddenly stopping in its current velocity, and interpolating to the direction. Also, it makes it a lot easier to implement things like ragdoll motion. (so, for example, I have a function to manually set the acceleration and velocity of certain bones) However, if there's a way to do this solely with interpolations, I'm all ears. (well, eyes ) Implementing a formula with quaternions - Frank C. - Oct 14, 2006 11:59 AM
>This article< describes "nlerp" rotations which are supposedly useful for IK. Tim Sweeny's got some code that might be helpful too. Implementing a formula with quaternions - akb825 - Oct 15, 2006 01:00 PM
Well, I think I'll give up on my original idea as impossible, at least with the amount of information I could find. Besides, I looked at the spline interpolations, and that's actually pretty much the kind of functionality I originally wanted. The only problem I can foresee is some potential jerkiness if I suddenly change what animation is next. Hopefully that will be doable by taking the last point in the last animation, the current point at the transition, and the next 2 points of the next animation. Implementing a formula with quaternions - unknown - Oct 15, 2006 01:26 PM
Its totally possible (now that I finally understand what you want to do), why not implement this kind of thing in 2D to get a hang of the maths? Then also get a firm grip on quaternion math by using them in some different test apps. Implementing a formula with quaternions - akb825 - Oct 15, 2006 02:39 PM
I could do it in 2D no problem, since there's only 1 angle that I need to worry about. However, with 3D angles (and 4D with quaternions), it gets much more complicated because rotations aren't commutative. (which is why it's pretty much a bad idea to add euler angles together; sometimes you get lucky, like I have when I added them before, but it's bitten me later when it didn't hold up) I have the formula that I need: d = vi*t1 + 1/2*a*t1^2 + vi*t2 + a*t1*t2, but the problem is I can't solve it for a without moving around the terms. If I move the terms around, I mess up the order of the rotations, which completely messes everything up. Now if you have a suggestion to solve this without re-ordering the terms, I'll certainly listen, but all my ideas haven't panned out. Implementing a formula with quaternions - unknown - Oct 16, 2006 04:24 AM
akb825 Wrote:d = vi*t1 + 1/2*a*t1^2 + vi*t2 + a*t1*t2 what are all the variables and in what form do you need the final equation? Implementing a formula with quaternions - akb825 - Oct 16, 2006 09:36 AM
d is the total rotation it will travel over the set time, vi is the initial angular velocity, a is the angular acceleration, and t1 and t2 are the time (t1 + t2 = total time). I know everything but a, which I'm solving for. Edit: oh, and the equation that I said in my first post, a = (d - vi*t)/(t1*t - 1/2t1^2), is what I get if I do combine the terms. (the bottom can also be t1*t2 + 1/2*t1^2, due to the relation that t1 + t2 = t; I got the first equation by solving differently, but it gives the same answer) |