MATLAB code to generate some parametric surfaces.Equation of the surface is mentioned on the image. The color of the surface in image may differ from that generated by the given MATLAB code.
Click the thumbnail to get a larger view.
Mobius Strip
[u,v]=meshgrid(linspace(0,2*pi,250),linspace(-0.8,0.8,50));
t=1; %number of twist
surf(sin(u).*(2-v.*sin(t*u/2)),cos(u).*(2-v.*sin(t*u/2))...
,v.*cos(t*u/2),u...
,'edgecolor','none','facecolor',[0.5 0.5 0.5]);
lighting phong
material([0.4447 0.6154 0.7919])
camlight headlight
daspect([1 1 1])
| 
| Swallow Tail [u,v]=meshgrid(-2:0.05:2,-0.8:0.05:0.8);
x= u.*v.^2 + 3*v.^4;
y= -2.*u.*v - 4*v.^3;
z= u;
surf(x,y,z...
,'facecolor',[0.5 0.76 0.1],'edgecolor','none');
lighting phong camlight headlight,camlight left
material dull axis off
daspect([1 1 1])
|
 | Bohemian Dome
[u,v]=meshgrid(-2*pi:0.05:2*pi,-2*pi:0.05:pi);
A=0.5;B=1.5;C=1;
surf(A*cos(u),B*cos(v)+A*sin(u),C*sin(v)...
,'facecolor',[0.1 0.67 0.89],'edgecolor','none');
camlight headlight,camlight left,camlight(1,-90)
material metal axis off
daspect([1 1 1])
|
 |
Enneper Surface
numPoint=50;
z = cplxgrid(100);
x=real(z);
y=imag(z);
r=1.1*abs(z);
phi=angle(z);
n =5;
x=r.* cos(phi)-r.^(2*n - 1).*cos((2*n - 1)*phi)./(2*n - 1);
y=r.* sin(phi)+r.^(2*n - 1).*sin((2*n - 1)*phi)./(2*n - 1);
z=2*r.^n.*cos(n.*phi)./n;
surf(x,y,z,phi)
%code for outer tube
rth=linspace(0,2.01*pi,300);
rradi = 1.1*ones(1,300);
rx=rradi.* cos(rth)-rradi.^(2*n - 1).*cos((2*n - 1)*rth)./(2*n - 1);
ry=rradi.* sin(rth)+rradi.^(2*n - 1).*sin((2*n - 1)*rth)./(2*n - 1);
rz=2*rradi.^n.*cos(n.*rth)./n;
cmap = makeColorMap(rand(1,3),rand(1,3),rand(1,3),128);
shading interp
colormap([cmap ; flipud(cmap)]);
tubeLines = {[rx' ry' rz']};
daspect([1 1 1])
h=streamtube(tubeLines,0.2,[1 70]);
set(h,'edgecolor','none','facecolor',[0.8 0.8 0.8]);
axis equal
lighting phong
camlight headlight
axis off
|
|
Torus
[U,V]=meshgrid(linspace(-2*pi,2*pi,100));
x=(7+3*cos(V)).*cos(U);
y=(7+3*cos(V)).*sin(U);
z= 3*sin(V);
surf(x,y,z,'facelighting','phong','edgecolor','none','facecolor',[0.5 0.5 0.5]);
material([0.2259 0.5798 0.7604]);
camlight headlight,camlight left
axis off equal
|

|
Astroidal Ellipsoid
[u,v]=meshgrid(-2*pi:0.05:2*pi,-2*pi:0.05:2*pi);
surf(cos(u).^3.*cos(v).^3,sin(u).^3.*cos(v).^3,sin(v).^3 ...
,'facecolor',[0.87 0.2 0.78],'edgecolor','none');
lighting phong
material(0.4447 0.6154 0.7919)
camlight headlight,camlight left
axis off
|

|
Mobius Strip
[u,v]=meshgrid(linspace(0,2*pi,250),linspace(-0.8,0.8,50));
t=4; %twist
surf(sin(u).*(2-v.*sin(t*u/2)),cos(u).*(2-v.*sin(t*u/2))...
,v.*cos(t*u/2),u...
,'edgecolor','none','facecolor',[0.5 0.5 0.5]);
lighting phong
material([0.4447 0.6154 0.7919])
camlight headlight
daspect([1 1 1])
|

|
Water Drop
[u,v]=meshgrid(linspace(0,2*pi,100),linspace(-5,4.4444,100));
x =v.^2.*sqrt((4-0.9.*v)./2).*cos(u);
y =v.^2.*sqrt((4-0.9.*v)./2).*sin(u);
z =v;
surf(x,y,z,z,'edgecolor','none','facecolor',[0.3 0.5 0.9]);
camlight headlight,camlight(1,-90)
material([0.7 0.4 0.6]);
daspect([1 1 0.1])
|

|
Spiral Wave surface
[x,y]=meshgrid(linspace(-5,5,100));
R=(x.*x+y.*y).^0.5;c=rand(1,3);
h=surf(x,y,1./(1+R).*(x.*sin(4*R)+y.*cos(4*R))...
,'facecolor',[0.4 0.7 0.8],'edgecolor','none');
lighting phong, camlight headlight,camlight left
material metal
axis off equal
|

|
Unknown
[u,v]=meshgrid(-0.1:0.02:2*pi);
surf(cos(u).*(-1 + 3*cos(v))...
,sin(u).*( 1 + 3*cos(v))...
,1.3* sin(v)...
,'facecolor',rand(1,3),'edgecolor','none');
camlight headlight,camlight left
material metal
daspect([1 1 1])
|

| Unknown
[u,v]=meshgrid(-pi:0.03:pi,-pi:0.03:pi);
surf(u.*v.*sin(3*v),v,u.*v.*cos(3*v)...
,'facecolor',rand(1,3),'edgecolor','none');
camlight headlight,camlight left
material dull
| 
|
p=2;
q=5;
t=linspace(0,2*p*pi,500);
x=(2+cos(q/p*t)).*cos(t);
y=(2+cos(q/p*t)).*sin(t);
z=sin(q/p*t);
verts = {[x' y' z']};
h=streamtube(verts,0.5);
set(h,'Facecolor',[0.6072 0.6299 0.3705],'edgecolor','none');
lighting phong
material dull
camlight headlight
axis off equal
view(3)
|
|
p=2;q=9;
|
|
p=4;q=3;
|
|
MATLAB code to project an image on a sphere.
testImage.png must be present in your current MATLAB directory.
x,y,z are original coordinates,X,Y,Z are projected coordinates.
[x,y]=meshgrid(linspace(-pi,pi,200));
%formula for projection
X=(2*x)./(1+x.^2+y.^2);
Y=(2*y)./(1+x.^2+y.^2);
Z=(-1+x.^2+y.^2)./(1+x.^2+y.^2);
img=imread('testImage.png');
hold on
h=warp(X,Y,Z,img); %projected image
warp(x,y,-1*ones(size(x)),img); %default image
hold off
axis equal
set(gcf,'color',[1 1 1]);
|
|
|
|