function x=hyperspherical(thetas)
% HYPERSPHERICAL Direction vector of a hyperspherical set of angles.
%
% x = hyperspherical(thetas) returns the directions from a set of angles
% that are hyperspherical direction 
%   see http://planetmath.org/encyclopedia/SphericalCoordinates.html

n = numel(thetas)+1;
x = zeros(n, 1);
x(1) = cos(thetas(1));
sinprod = 1;
for i=2:n-1
    sinprod = sinprod*sin(thetas(i-1));
    x(i) = sinprod*cos(thetas(i));
end
x(n) = sinprod*sin(thetas(n-1));

