function X = sph2cartm(sco)
% [ X ] = sph2cartm( sco )
% Transforms hypershperical to cartesian coordinates.
%
% Input:
%   sco     angles of spherical coordinates, last entry: radius
%
% Output:
%   X       cartesian coordinates
%
% Note: This function behaves different then matlabs sph2cart, but the same as matlabs pol2cart
% 
% E.g.: sph2cartm2(cart2sphm2([2 3 1]))
%       sph2cartm(cart2sphm([2 3 1]))
%
% See also: sph2cartm2, cart2sphm, sph2cartm, cart2sphm2
%
% Written by: tommsch, 2018

if(nargin==0 || isempty(sco)); X=[]; return; end;

r=sco(end);
sinval=sin(sco);
cosval=cos(sco);

dim=size(sco,2);
X=zeros(1,dim);
%XC=cell(1,dim);
cosval(end)=1;
for i=1:dim
    X(i)=prod([sinval(1:i-1) cosval(i)]);
%    XC{i}=[sinval(1:i-1) cosval(i)];
end
X=X*r;

end

function dummy; end %#ok<DEFNU> %Generates an error, if the 'end' of a function is missing.   