If you are planning to use one of the many Jacobian methods to compute Inverse Kinematics solutions, then you might be wondering how to compute a Jacobian matrix. You could either compute it numerically or analytically. This article will discuss how to compute the Jacobian analytically. Simply put, we will use cross products to compute the Jacobian.

Assuming we are working with the above articulated body, then we might want to compute the following Jacobian:

This Jacobian will get the end effector closer to the target position. There are other Jacobian matrices that have other goals besides positions (e.g., orientation), but we’ll focus on this simpler example for now.

So now the question is: How do we calculate each term in the matrix using an analytical form? Let’s look at the second term in the matrix:

For this term, we want to compute how far the end effector will translate if the joint B rotates counter-clockwise a differential amount (in the X axis). In other words, we are computing what is the instantaneous direction and magnitude if joint B rotates in a counter-clockwise fashion for a differential amount (and derive the X component from that direction and magnitude).

The way we would calculate this for any point rotating around an axis of rotation is finding the vector tangent to the point’s rotational path as shown below. In other words, finding the tangent to the circle.

The radius vector is represented by (E-B).

The rotating vector in this case is represented by (E-B). (E-B) is just the vector difference between the end effector and joint B. And we can define the axis for rotation for joint B as R_B. The way to compute the tangential vector (in the counter-clockwise direction) is by using the cross product of R_B and (E-B). By applying the right-hand rule, we can see that this will give us the tangential direction as expected. The distance between E and B will serve as the magnitude for the tangential vector. This makes sense because if the radius of rotation is increased, then the endpoint will travel a further distance for a given differential change in rotation. Please note that the magnitude of the tangential vector will be scaled down once the Jacobian is applied within the rest of the IK algorithm.

If we apply this logic to the rest of the joints in the articulated body, then we get a Jacobian matrix that is computed as follows:

The above is the calculation for each entry. The representation can be simplified by simply having each entry be a vector instead of a scalar, as follows:

R_A is simply the axis of rotation of joint A. E is the position of the end effector, as before. And A is the position of joint A. The same logic follows for the second and third columns in the Jacobian Matrix. Now we have all the mathematical elements to compute the Jacobian Matrix, this is what it would look like in code:

Matrix GetJacobian() {

J_A = CrossProduct(rotAxisA, endEffectorPos — jointAPos);

J_B = CrossProduct(rotAxisB, endEffectorPos — jointBPos);

J_C = CrossProduct(rotAxisC, endEffectorPos — jointCPos); J = new Matrix();

J.addColumn(J_A);

J.addColumn(J_B);

J.addColumn(J_C); return J;

}

The first line of code calculates the first column of the Jacobian matrix. The second line of code calculates the second column of the Jacobian matrix. The third line of code calculates the third column of the Jacobian matrix. Let’s take a look at the first line of code, which relates to joint A. The first line of code is a cross product of two terms. The first term is the rotation axis of joint A. The second term is the difference between the end effector position and the position of joint A. The second and third lines of code follow the same logic for joints B and C. Now, all we do is combine all three columns to form the whole Jacobian. And finally, we return the Jacobian matrix.

Some of this is overlap from the Overview of Jacobian IK. But hopefully, it explains more fully about the mathematical reasoning behind the usage of the cross product in the analytical computation for the Jacobian matrix.

If any IK jargon did not make sense, please review my Overview of Inverse Kinematics.