Finding point in a plane at fixed distances from 2 other points in the plane

85 Views Asked by At

This is a version of an inverse kinematics question where a robotic arm has fixed length upper and lower arms and you are provided with the shoulder and wrist locations but need to calculate the elbow position that is closest to the ground. So, there are three 3D points defining a plane, P1(x1,y1,z1) P2(x2,y2,z3) and P3(x3,y3,z3) (where P1 is the shoulder, P2 is the wrist and P3 is the "ground" in my example). I need to find another point A on that plane which is L1 length from P1 and L2 length from P2 and closest to P3 (out of the 2 possible positions that exist). I have found a solution for this in 2D (https://www.hindawi.com/journals/jr/2010/984823) but I am having difficulty extending it to 3D. enter image description here

function calculatePointFromLengths(p1,p2,l1,l2) {
  let L = sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
  let angleP1P2 = Math.atan((p2.y-p1.y)/(p2.x-p1.x));
  let theta1 = Math.acos(l1*l1+l2*l2-l2*l2)/(2*l1*L) + angleP1P2;

// now calculate the point using the angle

return( {
    x: p1.x + l1 * Math.cos(theta1);
    y: p1.y + l1 * Math.sin(theta1);
});
1

There are 1 best solutions below

3
On BEST ANSWER

Let $U = P_1 P_2 $ and $V = P_1 P_3$. First thing, project $V$ onto $U$

$\text{Proj}_U (V) = \bigg(\dfrac{ V \cdot U}{U. U}\bigg) U = Y_1 $

Next find the component of $V$ that is orthogonal to $U$, this is given by

$ V_{\perp} = V - \text{Proj}_U (V) = Y_2 $

Now normalize both $Y_1$ and $Y_2$ as follows

$ W_1 = \dfrac{Y_1}{\| Y_1\|} $

$ W_2 = \dfrac{Y_2 }{\| Y_2 \| } $

Finally compute the angle that $P_1 A$ makes with $P_1 P_2$, this is given by

$ \theta = \cos^{-1} \bigg( \dfrac{L^2 + L_1^2 - L_2^2 }{2 L L_1} \bigg) $

Now the point $A$ is given by

$ A = P_1 + L_1 \cos(\theta) W_1 + L_1 \sin(\theta) W_2 $