File talk:MathAcorn.png

From PrattWiki
Jump to navigation Jump to search

Code

The following is the MATLAB code to make the Math Acorn

clear
figure(1); clf

% Set number of points in each "direction"
Nr = 20; Nt = 37; Np = 20;

% Create spherical cap using spherical coordinates
[theta, phi] = ndgrid(linspace(0, 2*pi, Nt), linspace(0, asin(1/sqrt(2)), Np));
rho = sqrt(2);
xs = rho.*cos(theta).*sin(phi);
ys = rho.*sin(theta).*sin(phi);
zs = rho.*cos(phi);

% Create parabola using cylindrical coordinates
[r, theta] = ndgrid(linspace(0, 1, Nr), linspace(pi, 3*pi, Nt));
xc = r.*cos(theta);
yc = r.*sin(theta);
zc = xc.^2+yc.^2;

% Make projection plots
az = [0  45 0 90]
el = [90 30 0  0]
for k=1:4
subplot(2,2,k)
S1 = surfc(xs, ys, zs); shading faceted; colormap copper; hold on
S2 =surfc(xc, yc, zc); shading faceted
hold off 
if k~=2, axis([-1.1 1.1 -1.1 1.1 -.1 2.1])
else, axis equal
end
view([az(k), el(k)]); xlabel('x'); ylabel('y'); zlabel('z')
end

% Save file and convert to png
print -depsc MathAcorn
!convert MathAcorn.eps MathAcorn.png