martes, 9 de febrero de 2010

BALL RIG "GIMBAL LOCK"

This is a paper to make a ball roll in all axes simultaneously. I hope and be of great help.


UNIVERSIDAD La Salle Noroeste

Computer Animation IV

Enrique Rosales

Nubia Alejandra Barba Sosa

BALL RIG

Gimbal Lock

OBJECTIVE

Rolling a sphere on any axis over a given surface.

INTRODUCTION

This paper takes a look at the problem caused when Rolling a sphere on two of its axes at the same time. This problem is called ‘Gimbal Lock’. At the same time it shows and explains one of three possible solutions to Gimal Lock, using quaternions in 3DSMax.

DEVELOPMENT

PROBLEM DEFINITION

Now we are going to show one method where a sphere will roll on each one of their axes separately. This method is not a right solution to the problem, but it will help us analize what’s the problem

A continuación se muestra un método donde una esfera ruede en cada una de sus eje por separado. Este método no es la solución correcta, solo nos servirá para ver y analizar cual es el problema surge cuando la esfera se rota en dos direcciones al mismo tiempo.

First thing is create a Sphere and a Plane on 3D SMax, both on the position (0,0,0) of our scene, and set a name for each one:

Image plane and the sphere in position (0,0,0)

To make the sphere roll on a surface (in this case the plane) we must first daughther to the area of the plane selecting the “Select and Link” icon.

“Select and Link” icon.

After that the sphere must do this always above the plane, so if you change the radius to the sphere is always stay on top. For this we apply a WireParameters right clicking on the Sphere, then WireParameters-Transform-ZPosition then get a link, and select the field again, then Object (Sphere)-Radius.

Then a window opens where we put the radius affects the position "z" in the field, activating the arrow to the left and we put "connected", as shown in the image below:

Image of WireParameters Sphere

If we try to move the Sphere on its Z-axis, we will find that it is locked, and if we move the plane on the same direction, the sphere will move with it.

We applied a default checker material on the sphere, so we could more easily observe its rotation.

Image of Checker Material

If we move the sphere on either its X or Y axes from the perspective viewport, we can tell that it moves but does not rotate at all.

To make it spin, we need to use a mathematical expression.

To make the sphere rotate when you move the axes "x" or "y" need to put a mathematical expression that calculates how many radians has to rotate the sphere according to shift it has.

This mathematical expression is to be placed in the shaft it is desired to rotate when traveling on a given axis. For example, we go to the perspective view, select the “Reference Coordenate System” and put it Local, and see on that axis will rotate as the displacement that will have.

If we want to turn when it moves in the “x”-axis we see that the rotation is in the y-axis, therefore the mathematical equation will be applied to this rotation.

Then open the Curve Editor, and look in the rotation “y”-axis our sphere, we give you right click Assign Controller and a window with a list of drivers, select Float Expression. Expression Float allows you to generate your own variables and equations.

After selecting the driver opens a window, this window will create a variable called “posX”, to which you assign the value of the position "x" of the sphere, since in that axis will move to rotate.

Then create another variable called “radio”, this will be the radius of the sphere, as it is important to know how tall the radio for the perimeter of the area.

In the Expression box then put our mathematical equation as shown below.


The mathematical expression detToRad ((posX) / (2 * pi * radius)) * 360 is as follows:

• posX = as reminders to this variable we assign the value of the sphere in the “x”-axis, as this axis is to move to rotate the ball and need to know the position to which moved to get the value of rotation.

• Pi = is a reserved variable in 3DMax containing the value of the mathematical expression π (pi).

• Perimeter = is the equivalent of (2 * pi * radius) is the expression for the perimeter of the area, this variable varies with the radio.

• The value 360 is because a circle is 360 degrees in total.

• detToRad () = is a reserved function in 3DMax to convert degrees to radians.

To observe the rotation of the sphere gives evaluate button and then close the dialog box Expression Controller.

From the perspective view we can move the sphere on its axis "x" and see that the sphere rolls on the surface. Until this part we have managed to turn our area about an axis. To rotate the sphere when it moves in "and" we follow the same procedure, only the application according to the rotation required. In this case the position "and" affects rotation "x".

When finished, returns to the perspective view and move the field in each axis for separates, and you'll see that the wait wheel properly on the surface, however, without trying to move on two axes at the same time, you will see that produces an odd movement, this movement causes a problem called “Gimbal Lock”.

ANALYSIS OF THE PROBLEM

If we look in more detail our area, we can see that the rotate on two axes simultaneously starts correctly, but the more you move the rotation produces a wrong move.

Gimbal Lock is a phenomenon that occurs when two axes of rotation of an object point in the same direction. That is, it is exactly when you turn 90 degrees right object when trying to turn the same shaft in another axis, so that overlap and rotation is limited.

Previously, expression used by some drivers to make the rolling sphere, however, because of this problem there are other ways to make a ball roll on a surface correctly in any of its axes, separately or simultaneously.

SOLUTION OF THE PROBLEM

One of the possible solutions of this exercise is in the use of quaternions. When we make 3D animations, you need to have more value to the three already defined values (x, y, z). This value helps us define the interpolation of the orientations for the object roll naturally.

Quaternions are an alternative way to represent rotations through any axis. A quaternion is a 4D complex numbers representing the values of rotation through synodical and cosinodales functions.

A quaternion (Q) equals:

Quat q = (x, y, z, w) = (v x * sin (T / 2), y v * sin (T / 2), v z * sin (T / 2), cos (T / 2) )

As we know that the quaternions are a possible solution to our problem, we will use to open it again the Curve Editor and delete the controls of expression that we had assigned to rotations in our field by assigning the driver "Bezier Float" (controller default).

Then we looked for the rotation of our field and assign the controller "Rotation Script".

Image of Rotation Controller

Then a window opens where the script wrath of the sphere, so that this roll.

The first thing is to define the direction and distance to find this we need to get the previous and current position of our object.

Obj = $Esfera

Here we attach our object to the variable “obj” to manipulate it, in my case the object is called Sphere.

Timeres=1f

- It assigns the time in which to get previous and current position in this case is every 1 frame.

p0 = at time t0 obj.position

- Previous position

p1 = at time t1 obj.position

- Current position

dif = p1-p0

- The address is assigned to the variable "diff", this is achieved by subtracting the current position of the above, if positive, turn right, if negative turn left.

len = Length(dif)

- t assigns the distance traveled to the variable "len".

vec = dif / len

- We get the unit vector.

Once you have found the direction and distance traveled our area, we continue to find the axis of rotation. As the motion vector we can find the axis of rotation, as this is perpendicular to the motion vector, however there are several vectors perpendicular. Assuming that the surface (plane) is oriented horizontally, the force of gravity applied to it is the axis "z", the motion vector must also be perpendicular to this.

We can say that the axis of rotation can find travez of a cross-product of the motion vector with the vector of the axis "z" (0,0,1). In 3DMax there a function to find this product:

Rotax= vec cross[0,0,1]

Since we have the rotation axis, we find the amount that will rotate on that axis. If the area goes round would have to travel a distance equal to its circumference (perimeter). Then if we divide the distance traveled our area, including the circle, we know how many laps you have to take to get that close.

Angle = 360*len/((r0+r1)*PI)

The values r0 and r1 are the radio exchange that have been made at different times.

Once you have the axis of rotation "rotax" and the amount of times they will turn "angle" you can build your quaternions. 3D Max function exists to do this.

rotdif = quat angle rotax -- Get the quaternion

rot1 = rot0 + rotdif -- Add the value of the rotation quaternion above for the final rotation.

Knowing the script for the sphere turn, put the code in the field of Expression of the Controller Assing window.

The final code is:

obj = $Esfera - the object is assigned to the variable in my case is Sphere

timeres = 1f - time in which we obtain the previous and current position in this case is every 1 frame

fn getrot t = - Function which calculates the rotation

(

if t<=0f then return quat 0 0 0 1 -- t=0 => -- Checked for movement

t0 = t-timeres - Previous Time

t1 = t - Current Time

rot0 = getrot(t0) - It assigns the previous rotation

p0 = at time t0 obj.position -It assigns the previous position

p1 = at time t1 obj.position -It assigns the current position

if(p0==p1) then return rot0 Is calculated if there was movement, if p0 and p1 are equal then it has motion

dif = p1-p0 - calculate the direction

len = Length (diff) - calculate the distance

vec = diff / len - We obtain the motion vector

r0 = at time t0 obj.radius - Get previous radio

r1 = at time t1 obj.radius - Get the current radio

rotax = cross vec [0, 0, 1] - We get the axis of rotation

angle = 360 * len / ((r0 + r1) * pi) -get the amount of money you have to take the field

rotax rotdif = quat angle - We get the rotation quaternion

Rot1 = rot0 + rotdif - calculate the total rotation

)

getrot (currentTime) -call the function with the current frame

Image of the Sphere Script

Once the script because the area, give it to evaluate and close the dialog box.

Create an animation where you move the dial, so you can see the rotation.

CONCLUSION

To roll a sphere on a surface is necessary to take into account the effect of Gimbal Lock, if we rotate on two axes simultaneously. A quick and easy way to fix this phenomenon is by using quaternions. This does not mean it's the only solution to this problem however, unlike others it is considered more quickly and effectively.

Quaternions are an alternative way to represent rotations through any axis. A quaternion is a 4D complex numbers representing the values of rotation through synodical and cosinodales functions.

If the quaternions are working under the weather, so it is necessary to have an animation to see the effect.

Thank’s.

REFERENCES

http://www.cuneytozdas.com/tutorials/maxscript/

http://en.wikipedia.org/wiki/Quaternion

http://en.wikipedia.org/wiki/Gimbal_lock

No hay comentarios:

Publicar un comentario