A small arm on a bakery line moves cookies from the oven belt onto trays. Seen from above it is a planar two-link arm: a shoulder joint fixed at the origin, a first link of length l1, an elbow joint, and a second link of length l2 that ends in the gripper (the hand).
The two joint angles are in radians, measured counter-clockwise, and they are relative:
t1is the angle of the first link, measured from the +x axis;t2is the angle of the second link, measured from the direction of the first link (sot2 = 0means the arm is stretched straight).
The world frame has x to the right and y up. Write two_link_hand(l1, l2, t1, t2) that returns the hand position as a tuple (x, y).
Examples
Input: l1 = 2, l2 = 1, t1 = 0, t2 = math.pi / 2
Output: (2.0, 1.0)
Explanation: the first link lies along +x to (2, 0); the elbow bends a quarter
turn to the left, so the second link points straight up and ends at (2, 1).
Input: l1 = 0.5, l2 = 0.3, t1 = math.pi / 2, t2 = math.pi / 2
Output: (-0.3, 0.5)
Explanation: the first link points up to (0, 0.5); the second turns another
quarter turn from there, so it points along -x.
Input: l1 = 0.4, l2 = 0.3, t1 = 0.5, t2 = -1.2
Output: (0.58048568, -0.00149509)
Constraints
- answers are compared with a tolerance of
1e-6; do not round
Goals
- Place each link's end with `cos` and `sin` of its absolute direction
- Turn relative joint angles into absolute directions by adding them up
- Add the two link vectors to find the hand