% dforceR.m
% forces on link (i) 
function out=dforceR(rAi_,rAj_,rCi_,Fi_,Mi_,Fji_)
% rAi_ is the position vector of Ai
% rAj_ is the position vector of Aj
% rCi_ is the position vector of CM of (i)
% Fi_ total forces on (i) at Ci including
%     the inertia force at Ci and 
%     the gravitational force at Ci
% Mi_ is the total moment on (i) including
%     the moment of inertia on (i)
% Fji_ is the reaction force of (j) on (i) at Aj

% sum forces of (i)
% FAi_ + Fi_ + Fji_ = 0_ ; =>
% FAi_ rection force on (i) at Ai
FAi_ = - Fi_ - Fji_;

% equilibrium motor
% sum of moments of (i)  about Ai
% AiCi_ x Fi_ + AiAj_ x Fji_ + Mi_ = 0_ =>
% Mm_ is the equilibrium moment or motor moment
Mm_ = -cross(rCi_-rAi_,Fi_)-cross(rAj_-rAi_,Fji_)-Mi_;
 
out = [FAi_(1), FAi_(2), Mm_(3)];
end