I found a Web Site which explains Inverse Kinematics in 2D:
Starting from the joint nearest the
end point:
1. Calculate a force vector from the end of the bone to the target.
2. Calculate the dot product of the force vector and the Right angle
vector.
3. Multiply it by a small value, like 0.01.
4. Add it to the angle of the joint.
http://freespace.virgin.net/hugo.elias/models/m_ik.htm
So the way the bones are designed in my application is in terms of a joint and an angle. Each 'bone' is a joint and an angle and a length. The bone's end point is then the unit vector of its starting point and ang开发者_如何学Gole, multiplied by its length.
So I think for step 1, I simply generate a unit vector whos direction points toward the target and multiply it by the distance between the end point and the target point.
Step 2 is where I'm unsure. I know how to produce a dot product, but I'm not sure how to get this right angle vector they speak of.
Thanks
The "right angle vector" is a vector that is at a right angle to the length of the bone.
If you are pushing the bone along its length, it shouldn't move. In this case, the angle between this "right angle vector" and your force vector is then 90 degrees, and so the dot product is zero. Hence, no change in angle of the bone.
The Right-Vector is the R-Vector in the pictures of the 2D-inv-kinematics-sections. It is a normalized vector orthogonal to the bone.
A small hint: the dot-product of vector A and a normalized vector B is just the projected length of vector A to the straight of vector B which is just the cos(angle). More details here: http://en.wikipedia.org/wiki/Dot_product#Geometric_interpretation
As a result if the target-vector is nearly the same as the right-vector then the cos will be near 1 and the algorithm will correct your bone-angle more than if the target-vector is nearly the same as your bone-vector (cos is near 0)
精彩评论