% SPHEAD generates a spherical head (and its counterpart as well as
% cutting plane)
%
% USAGE: [xh, yh, zh, xs, ys, zs] = sphead (N, th, off)
%
% parameters: N quantisation level
% th bounding angle of version space
% off specifies, by which amount the head should be off
% the sphere
% x x-coordinates of the mesh grid (s for sphere, h for head)
% y y-coordinates of the mesh grid (s for sphere, h for head)
% z z-coordinates of the mesh grid (s for sphere, h for head)
% th truely taken theta
%
% (c) 2001 Microsoft Corporation. Reproduced with permission. All rights reserved.
function [xh, yh, zh, xs, ys, zs, th] = sphead (N,th, off)
N1 = round (th/pi*N);
N2 = N - N1 + 2;
dth = pi/N;
xs = zeros (N1,N);
ys = zeros (N1,N);
zs = zeros (N1,N);
xh = zeros (N2,N);
yh = zeros (N2,N);
zh = zeros (N2,N);
%% create sphere
theta = -dth;
for i=1:N1
theta = theta + dth;
for j=1:N
phi = 2*pi/(N-1)*(j-1)-pi;
xs (i,j) = cos (phi) * cos (theta - pi/2);
ys (i,j) = sin (phi) * cos (theta - pi/2);
zs (i,j) = sin (theta - pi/2);
end
end
%% create head
th = theta;
theta = theta - dth;
for i=1:N2
theta = theta + dth;
for j=1:N
phi = 2*pi/(N-1)*(j-1) - pi;
xh (i,j) = cos (phi) * cos (theta - pi/2);
yh (i,j) = sin (phi) * cos (theta - pi/2);
zh (i,j) = sin (theta - pi/2) + off;
end
end