RyanJuckett.com

Constraint Relaxation IK in 2D - Resolving Constraints Print E-mail
  
Monday, 13 April 2009 00:00
Article Index
Constraint Relaxation IK in 2D
Reaching the Target
Resolving Constraints
Implementing for Higher Dimensions
Local Minima
Writing the Code
All Pages

  

Resolving Constraints

When resolving a distance constraint for a bone, we have two end points and the constrained length between them. End point \mathbf{b_1} will be base of the current bone. End point \mathbf{b_2} will be the base of the child bone. Length l_1 will be the desired distance between \mathbf{b_1} and \mathbf{b_2}. We will also support positive relaxation weights, w_1 and w_2, corresponding to the end points. The higher an endpoint is weighted, the more that endpoint will move in the solution. If an endpoint is given a zero weight, it will not move at all. If both end points are given the same weight, they will move equal distances.

 

As a first step, we can check the bone weights for a cases that implies we shouldn't do any work. If the total weight, w_1 + w_2, is zero neither joint should move and the constraint is skipped.

 

Next we check if the squared distance between the end points is zero. Let \mathbf{v} = \mathbf{b_2}- \mathbf{b_1} and then use the dot product \mathbf{v} \cdot\mathbf{v} to get the squared distance. If the result is zero, it implies that the end points are directly on top of each other. This makes it a bit hard to choose the best direction for stretching the bones. We will instead skip constraints in this situation with the hope that either later in this iteration or on a following iteration the points will be stretched apart by one of the neighboring constraints being resolved.

 

Now that we have found a constraint to modify, we need to compare the distance between the end points with the given bone length l_1. The distance between \mathbf{b_1} and \mathbf{b_2} can be calculated as d = \sqrt{ \mathbf{v} \cdot \mathbf{v}}.

 

We need to adjust the current distance by l_1-d. We can now compute a vector that would move \mathbf{b_2} the appropriate distance from \mathbf{b_1} by normalizing \mathbf{v}, and rescaling it to the desired change in distance, l_1-d. This gives us a new vector \mathbf{u} = (l_1-d)\frac{\mathbf{v}}{d}.

 

Rather than directly adding \mathbf{u} to \mathbf{b_1}, we want to distribute it across \mathbf{b_1} and \mathbf{b_2} based on the relaxation weights. Note that when modifying \mathbf{b_1} we will be subtracting \mathbf{u} to move the endpoint in the opposite direction.

 

To distribute the weighted modification across both joints, we will use the following equations.

\mathbf{b_1}=\mathbf{b_1}-\mathbf{u}\frac{w_1}{w_1+w_2}

\mathbf{b_2}=\mathbf{b_2}+\mathbf{u}\frac{w_2}{w_1+w_2}

 

 Our joints are now at the appropriate distance and the constraint has been resolved.

  



Last Updated ( Sunday, 02 May 2010 06:30 )
 

Creative Commons License
RyanJuckett.com site content by Ryan Juckett is licensed under a Creative Commons Attribution 3.0 United States License.