Game Development Reference
Figure 9.2 A single link IK chain.
this problem we have a target position indicated in Figure 9.2 using a
cross. We also have a single link object. We want to orientate the object
so that it points towards the cross. To achieve this we have only to
calculate the value of
, the rotation angle. This is an exercise in simple
trigonometry. We know the x distance to the target is target x minus object
x and the y distance can calculated the same way. The y distance divided
by the x distance gives the tangent of the angle, so the simple solution is
found by calculating the inverse of the tangent of the y distance divided by
the x distance.
The simple solution to this problem is
= atan( y distance/ x distance)
The demo for this can be run by selecting Chapter09/Ikdemo.exe and
selecting 'Single Link' from the menu.
Calculating the orientations for a double link IK chain
By adding a single extra link, the problem becomes much more complex.
Consider Figure 9.3; the intention is to calculate both
values based on
the position of the target. Assuming we know the length of each link
(Length1 and Length2), we can state that
Pivot2. x = Pivot1. x + Length1 * cos(
Pivot2. y = Pivot1. y + Length1 * sin(