# Quaternion rotation curve

This topic is 3084 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,

i'm using Unity 3D engine for a certain project. In the project I need to create animation curves on-the-fly.

In Unity, animation curves are represented as keyframes containing (Time, Value, InTangent, OutTangent). Each component of each possible transformation is represented a single curve (for example, rotation is represented using 4 curves, one for each of the four quaternion components (x, y, z, w)). So, in total there are 10 curves(3 position(Vector3), 3 scale(Vector3), 4 rotation(Quaternion))

For example, if i wanted to create animation that moves an object on the x axis by 5 units in 1 time unit I would add a curve for "Position.x" with two keyframes (0, 0, 0, 0), and (1, 5, 0, 0). As you can see, InTangent and OutTangent are set to zero, as I simply want linear interpolation between the two keyframes.

However, when doing rotation, InTangent and OutTangent need to be set to some value, and I don't know how to calculate that value. What I want to know, is what could InTangent and OutTangent variables be, and how to calculate them? All I know, is that they are at 0 when I want linear interpolation.

Unity describes InTangent and OutTangent as:
InTangent - Describes the tangent when approaching this point from the previous point in the curve.
OutTangent - Describes the tangent when leaving this point towards the next point in the curve.

But I don't know how to calculate those tangents when I want rotation.

EDIT:

Just to make it easier to visualize:

I have curve on the left, and I want to get the curve on the right. And I get that curve by properly setting the InTangent and OutTangent values at each of the keyframes. (This is done using Unitys animation editor, that does this automatically).

##### Share on other sites
If the first point on your graph is A, then 2nd is B, and the third is C, you should be able to calculate this by:

1) Calculate vector AB and normalize it
2) Calculate vector BC and normalize it
3) Average the vectors and re-normalize to get one of the tangents
4) multiply by -1 to get the other tangent

I think that ought to work (:

##### Share on other sites
That seems to be it, thank you :)

##### Share on other sites

you might try playing around with the length of the normal vectors too if the curve isn't smooth enough.

IE at the end the vectors are normalized so they are a length of 1. If you multiply them by 2 (or other numbers > 1) it should make the curve smoother if you need it to be.

Or if it's too smooth, you can multiply by a number between 0 and 1 too (:

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633709
• Total Posts
3013481
×