Wednesday, August 22, 2012

Updating the tangent to circle constraint

As mentioned in yesterday's post, I'm updating the constraints so that their calculation in the solver is faster and the partial derivatives are calculated instead of being approximated as they are now.

A line tangent to circle constraint is equivalent to a point to line constraint, where the point is the center of the circle and, following the demonstration here we have the following formula for the constraint function:

For the partial derivative calculation we have two cases: where the variable doesn't appear in the denominator, and when it does. For the first case, the result is obvious. For the second case, we need to use these three formulas:

After applying these, we obtain:

which can be further simplified by using the old dx and dy notations:

the formula becomes:

and the sign is given by the value of the module evaluation (if the value inside the absolute module is negative, the entire expression is multiplied by -1 because we've been differentiating an absolute value.

With some small modifications, the same formula will be used for the radius tangent constraint and after a structure update for the point to line constraint, it will be used there, as well.

No comments: