function [x,y,z] = dInitial(d,tt)
% returns initial points


n = size(d,2);
R = sqrt(1/3)*mean(mean( d(1:n,1:n) ));
d12 = mean(d(1,1:2)); d23 = mean(d(1,2:3)); d13 = mean(d(1,[1,3]));
s = (d12+d13+d23)/2;
h = 2*sqrt(s*(s-d12)*(s-d23)*(s-d13));
x = [0 d12 sqrt(d13^2-h^2)]';
y = [0 0   2*s/d13]';          
z = [0 0   0]';    
[x,y,z] = dMinNoZero(x,y,z, d(1:3,1:3), tt(1:3,1:3));
N = 5;
for(i=4:n),
disp(i);
   % generate N random points
   [xnew, ynew, znew] = dRandPoints( N, R);

   % calculate error for the new points
   for j=1:N,
       error(j) = ( tt(i,1:i-1) + tt(1:i-1,i)') * ...
        ((xnew(j)-x(1:i-1)).^2 + (ynew(j)-y(1:i-1)).^2 + (znew(j)-z(1:i-1)).^2)...
        - (tt(i,1:i-1)*d(i,1:i-1)' + tt(1:i-1,i)'*d(1:i-1,i));
   end;   

   % find the point the minimal error and add it to the list of points
   [emin, a] = min(error);
   x = [x; xnew(a)]; y = [y; xnew(a)]; z = [z; xnew(a)]; 

   % minimize
   [x,y,z] = dMinNoZero(x,y,z, d(1:i,1:i), tt(1:i,1:i));

end;

return



