1
function seashell (a, b, c, n, azimuth, elevation, res)
2
% SEASHELL draws a pretty Florida seashell, using a 3D parametric surface.
6
% seashell (a, b, c, n, azimuth, elevation, res)
9
% All arguments are optional. The first four control the coefficients of
10
% the parametric surface (u and v are the surface parameters):
12
% x = (a*(1-v/(2*pi)).*(1+cos(u)) + c) .* cos(n*v) ;
13
% y = (a*(1-v/(2*pi)).*(1+cos(u)) + c) .* sin(n*v) ;
14
% z = b*v/(2*pi) + a*(1-v/(2*pi)) .* sin(u) ;
16
% a,b: these determine how pointy or flat the shell is (informally...)
17
% c: determines how much the shell overlaps with itself
18
% n: the number of spirals in the shell
20
% azimuth, elevation: determines the viewing angle (see the 'view' function)
21
% res: the mesh size (res-by-res). A larger number gives a smoother surface.
23
% If the azimuth is Inf, then the seashell view is spun dynamically.
24
% Also try seashell ('spin') ;
27
% T. Davis & K. Sigmon, MATLAB Primer, 7th edition, CRC Press, 2005, pp. 80.
28
% von Seggern, CRC Standard Curves and Surfaces, 2nd edition, CRC Press,
32
% seashell ; % draws the front cover of the MATLAB Primer
33
% seashell (-0.5) ; % draws the back cover
34
% seashell (a,b,c,n,az,el,res) ; % all options, defaults:
35
% % a=-0.2, b=0.5, c=0.1, n=2, az=-150, el=10, res=128
46
% See also SHELLGUI, SURF, VIEW, LINSPACE, MESHGRID, SHADING, LIGHTING,
47
% LIGHTANGLE, COLORMAP, AXIS, MATERIAL, SIN, COS, PI.
49
% Copyright 2006, Tim Davis, University of Florida
51
% use default input parameters, if not present
52
if (nargin == 1 && ischar (a))
90
% construct the res-by-res mesh
91
t = linspace(0, 2*pi, res) ;
95
x = (a*(1-v/(2*pi)).*(1+cos(u)) + c) .* cos(n*v) ;
96
y = (a*(1-v/(2*pi)).*(1+cos(u)) + c) .* sin(n*v) ;
97
z = b*v/(2*pi) + a*(1-v/(2*pi)) .* sin(u) ;
111
% fix the view, or spin the seashell
112
if (isfinite (azimuth))
113
view([azimuth elevation])
116
view ([az elevation])