Code covered by the BSD License

# Spherium

### Andrew French (view profile)

05 Jul 2011 (Updated )

Wield the power of OpenGL and create ammonites, Klein bottles and curious spheria!

```%make_ammonite
% Function which creates a 3D ammonite.

bump_amplitude, ridge_frequency, spiral_bump_amplitude, spiral_bump_frequency, helicity )

% Define spiral function. r is range, t is angle measured clockwise from y
if strcmp( spiral_type, 'Archimedian' )
spiral_func_str = 'r = (t/2*pi).^2';
elseif strcmp( spiral_type, 'Linear'  )
spiral_func_str = 'r = t/(2*pi)';
else
%Logarithmic spiral
spiral_func_str = 'r = exp(t/(2*pi)) - 1';
end

%Define array of cross section angles alpha
alpha = linspace(0,2*pi,points_per_turn);

%Define array of spiral angles t
t = linspace(0,2*pi*spiral_turns,points_per_turn*spiral_turns);

%Mesh these
[alpha,t]=meshgrid(alpha,t);

%Define cross section ellipse semi-major radii
R = 0.5*spiral(t+2*pi,spiral_func_str) - 0.5*spiral(t,spiral_func_str);

A = R.*( sin(alpha).^2 + cross_section_ratio*cross_section_ratio*cos(alpha).^2 ).^(-0.5);

A = A.* ( bump_amplitude*cos(ridge_frequency*alpha) + 1 );
end
C = A.* ( bump_amplitude*cos(ridge_frequency*alpha) + 1 );
else
C=A;
end

A = A.* ( spiral_bump_amplitude*cos(spiral_bump_frequency*t) + 1 );
end
C = C.* ( spiral_bump_amplitude*cos(spiral_bump_frequency*t) + 1 );
end

%Define cross section ellipse Cartesian coordinates
a = A.*sin(alpha);
x = A.*cos(alpha)+helicity*t;

%Determine surface in x,y,z coordinates
k = a + 0.5*spiral(t+2*pi,spiral_func_str) + 0.5*spiral(t,spiral_func_str);
y = k.*sin(t);
z = k.*cos(t);
R = sqrt( x.^2 + y.^2 + z.^2);
Rmax = max(max(R));
x = x./Rmax;
y = y./Rmax;
z = z./Rmax;
C = C./Rmax;

%Create surface and return a handle to it
surface_handle = surf(x,y,z,C);
axis equal
axis vis3d
axis off

%%