% linvelacc.m
% linear velocity and acceleration
function out=...
 linvelacc(rP_,rQ_,vP_,aP_,omega,alpha)
% rP_ is the position vector of P
% rQ_ is the position vector of Q
% vP_ is the velocity vector of P
% aP_ is the acceleration vector of P
% omega is the angular velocity of PQ
% alpha is the angular acceleration of PQ

% position, velocity, acceleration of P
xP = rP_(1);
yP = rP_(2);
vPx = vP_(1);
vPy = vP_(2);
aPx = aP_(1);
aPy = aP_(2);

% position of Q
xQ = rQ_(1);
yQ = rQ_(2);

% velocity of Q
vQx = vPx - omega*(yQ - yP);
vQy = vPy + omega*(xQ - xP);

% acceleration of Q
aQx = aPx - alpha*(yQ - yP) - omega^2*(xQ - xP);
aQy = aPy + alpha*(xQ - xP) - omega^2*(yQ - yP);

% components of linear velocity and acceleration of Q
out = [vQx vQy aQx aQy];
end