The basic idea is to find the position of the elbow using the positions of the shoulder and hand by considering the triangle formed by the shoulder, elbow and hand.
Since we know the lengths of the upper arm and forearm, and we can calculate the distance between the shoulder and the hand on each frame, we know all three sides of this triangle.
We can then use the law of cosines to find the angle between the upper arm and the line from shoulder to hand. And we can then find the angle between the x-axis and the line-from-shoulder-to-hand using the inverse tangent function, plugging in the dy and dx of hand relative to shoulder.
The sum of these two angles is equal to the angle between the upper arm and the x-axis. Since we know the length of the upper arm we can now solve for the elbow x and y point by multiplying this length by the cosine and sine of the angle we've found and adding these x and y components to the shoulder position.
Overview with visuals: • Inverse Kinematics: Solving for up-ar...
Law of Cosines review: • Solving for an angle using Law of Cos...
Code: https://editor.p5js.org/rjgilmour/ske...
Support my channel: https://ko-fi.com/morejpeg
0:00 Joint position objects
0:57 Connecting points to draw the arm
1:35 Drawing circles at joints and hand
2:19 Click and drag the hand
3:15 Defining upper and forearm lengths
3:55 Defining the angles needed to find elbow position
5:13 Writing the IK Function
8:55 Calling the IK Function
9:25 Results
#codingchallenge #javascript # creativecoding
Watch video Coding an Inverse Kinematic arm in 10 minutes online without registration, duration hours minute second in high quality. This video was added by user morejpeg 18 January 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,94 once and liked it 6 people.