I'm trying to draw a sea shell using PGF/TikZ. The shape of the shell is based on a set of parametric equations plotted in 3D. (Source: Math Parametric Equation for Seashell)
For those familiar with MATLAB, I've written some code which gives a working solution:
R=1; % Radius
N=3.6; % Number of turns
H=2; % Height
P=2; % Power
samples = 100;
[x,y] = meshgrid(0:2*pi/(samples-1):2*pi);
X = (x/(2*pi*R)).*cos(N*x).*(1+cos(y));
Y = (x/(2*pi*R)).*sin(N*x).*(1+cos(y));
Z = (x/(2*pi*R)).*sin(y) + H*(x/(2*pi)).^P;
% PLOTTING
surf(X,Y,Z,X)
set(gca,'ZDir','reverse')
axis off
axis equal
shading interp
material dull
lighting gouraud
lightangle(80,-40)
lightangle(-90,60)
This is what I've achieved so far in LaTeX, based off this answer from How to draw a Torus:
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\R}{1}
\pgfmathsetmacro{\N}{3.6}
\pgfmathsetmacro{\H}{2}
\pgfmathsetmacro{\P}{2}
\begin{axis}
\addplot3[
surf,
colormap/cool,
samples=60,
domain=0:2*pi,
y domain=0:2*pi,
z buffer=sort]
({(x/(2*pi*\R))*cos(\N*deg(x))*(1+cos(deg(y)))},
{(x/(2*pi*\R))*sin(\N*deg(x))*(1+cos(deg(y)))},
{(x/(2*pi*\R))*sin(deg(y)) + \H*(x/(2*pi))^\P});
\end{axis}
\end{tikzpicture}
\end{document}
Can anyone help get this looking better? I've been trying to reverse the z
axis, make the axes equal and remove the axes lines and labels. Additionally, I'm unsure of the capabilities of PGF/TikZ when it comes to things like shading and lighting. So would be interested to know what can be achieved.
sin(\N*deg(x))
instead ofcos(\N*deg(x))
. Then it looks fine, see this screenshot with 100 samples.z dir=reverse
.