% Displays a 3-D donut
% Minas Spetsakis, Nov. 2017

res = 50;
R = 10;
r = 3;
phi = linspace(0,2*pi,res);
theta = linspace(-pi,pi,res);
X = zeros(res);
Y = zeros(res);
Z = zeros(res);

for i=1:res
    for j=1:res
        X(i,j) = R * cos(phi(i)) + r*cos(theta(j))*cos(phi(i));
        Y(i,j) = R * sin(phi(i)) + r*cos(theta(j))*sin(phi(i));
        Z(i,j) = r * sin(theta(j));
    end;
end;
mesh(X,Y,Z);
daspect([1,1,1]);
