|
Page 2 of 5
Optimizing a joint
In math, optimization in the process of finding a value that will minimize or maximize a function. In our case, we want to minimize the distance between the end effector and the target (i.e. minimize for end effector, , and target, ). Depending on how our joints behave, different equations will be used to find the optimal solution. For example, one joint might allow for translation while another joint might allow rotation.
For common joint behavior, we can develop an analytic solution to find the optimal value. I am going to walk through solving the optimization problem for rotational joints (the most common joint behavior in an animated character).
As a rotational joint, we can rotate the end effector in a circle about our position (see figure 1). The closest position to the target on our rotational circle is the intersection of the circle and the line segment between the current joint and the target.

figure 1
To move the end effector to its optimal position, we need to rotate the joint by the unknown value . We know the current joint position, , the current end effector position, , and the target position, . To find , we need to find the angle that will rotate around onto the line . This makes the signed angle between the vectors and that rotates to .
Solving for cosine
The dot product can be geometrically interpreted as where is the length of vector , is the length of vector , and is the smaller angle between vector and vector . Using this formula, we can solve for the cosine of .
 \cdot (\mathbf{t} - \mathbf{j}) = |\mathbf{e} - \mathbf{j}| |\mathbf{t} - \mathbf{j}| \cos \alpha)
 \cdot (\mathbf{t} - \mathbf{j})}{|\mathbf{e} - \mathbf{j}| |\mathbf{t} - \mathbf{j}| })
Solving for sine
The cosine alone will help us find the magnitude of , but it won't supply us with the direction of rotation. To find the direction, we need to compute . The three-dimensional cross product can be geometrically interpreted as where is the unit vector perpendicular to vector and vector pointing in the direction defined by the right-hand rule, and is the unsigned smaller angle between vector and vector . While is an unsigned angle, we will be able to get the direction of our rotation based on the direction of 
First, let's expand the cross product of two three-dimensional vectors.

If we interpret our two-dimensional vectors as three-dimensional vectors on the xy-plane, the cross product will result in a three dimensional vector pointing along the z-axis.

Looking back at our geometric interpretation of the cross product, , the unit vector must be either the negative or positive z-axis. Combining our expanded cross-product with the geometric interpretation, we get the following relation where is either -1 or 1.

We can now focus on the z-components of our equation (x and y were zeros).

The value of determines if we are rotating in clockwise or counter-clockwise direction. In a right-handed coordinate system where the x-axis points right and the y-axis points up, the z-axis will point forward. According to the right-hand rule, will be the negative z-axis when we are rotating clockwise and will be the positive z-axis when we are rotating counter-clockwise. This implies that is -1 for clockwise rotations and 1 for counter-clockwise rotations.
Because is the smaller angle between two vectors, it is in the positive range . Positive angles result in counter-clockwise rotations. Negative angles result in clockwise rotations. Given that , when is -1, . Previously, we concluded that a negative value of implies a clockwise rotation which in turn implies a negative rotation angle. This will let us define a new signed angle, that is the directional rotation from vector to vector .


Using this equation, we can substitute for , , and to solve for the sine of .
(t_y - j_y)-(e_y - j_y) (t_x - j_x) = |\mathbf{e} - \mathbf{j}| |\mathbf{t} - \mathbf{j}| \sin \alpha)
(t_y - j_y)-(e_y - j_y)(t_x - j_x)} {|\mathbf{e} - \mathbf{j}| |\mathbf{t} - \mathbf{j}|})
We now have equations for solving the sine and cosine of a signed angle between two vectors. This will let us perform the appropriate rotation for our joint.
|