% pos3P.m
% position 3 points on a line  P, Q, R
function out = pos3P(rP_, rQ_ , PR)
% rP_ is position vector of P
% rQ_ is position vector of Q
% PR  is length of the segment PR
% select
% +PR if R is on the same direction from P to Q  P->R->Q or P->Q->R
% -PR if R is opposite to the direction from P to Q  R->P->Q 

% coordinates of P
xP = rP_(1);
yP = rP_(2);
% coordinates of Q
xQ = rQ_(1);
yQ = rQ_(2);

% orientation of line PQ
PQ = norm([xQ-xP, yQ-yP]);
cPQ = (xQ-xP)/PQ;
sPQ = (yQ-yP)/PQ;

% coordinates of R
xR = xP + PR*cPQ;
yR = yP + PR*sPQ;

out = [xR yR];
end