Implementing a formula with quaternions
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)
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)
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 noncommunitive 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. )
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.
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.
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/Documentat...rnions.pdf
All I can recommend is you read and understand this, http://www.geometrictools.com/Documentat...rnions.pdf
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
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?
Edit: why does every place use a different slash for that smilie?
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
If you can linearly or spherically interpolate, you're 99.9% of the way there, then.
Jon
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 )
>This article< describes "nlerp" rotations which are supposedly useful for IK. Tim Sweeny's got some code that might be helpful too.
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.
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.
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
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 reordering the terms, I'll certainly listen, but all my ideas haven't panned out.
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?
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
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)
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)
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Quaternions in 2D  Frank C.  7  11,893 
Jun 28, 2012 04:21 PM Last Post: Charybdis 

Implementing page views.  MacSteve85  2  3,527 
Jan 20, 2010 12:09 AM Last Post: cmiller 

Kinematics with Quaternions  akb825  3  5,022 
Sep 19, 2006 04:34 PM Last Post: akb825 

Implementing Portals  Ingemar  0  2,567 
Jun 29, 2005 04:42 PM Last Post: Ingemar 

World and Object Rotations (Quaternions Are Killing Me)  Nickolei  3  4,522 
Feb 14, 2005 06:12 PM Last Post: Nickolei 