# Revision history [back]

Here is a translation of the code. Colors are not yet possible, see http://trac.sagemath.org/ticket/12212

"""
Code traduit depuis Maple, le code original est ici:

http://www.maplesoft.com/applications/view.aspx?SID=3851&view=html#mapleautobookmark9

REFERENCES:

A. Cortie : *Digital Seashells* Comput & Graphics Vol 17 , pp. 79-84 (1993)
"""
pi = float(pi)

"""
"""
return float(aa) / 360 * 2 * pi

def Natalina():
"""
un modele simple
"""
dic = {'D': 1,
'A': 25, 'a': 12, 'b': 16, 'P': 0, 'L': 0}
trange = (-2 * pi, 4 * pi)
grid = [100, 100]
return dic, srange, trange, grid

def Lyria():
"""
un autre modele
"""
'Omega': rad(-2), 'A':50, 'a':40, 'b':14, 'P':0, 'L':8,
trange = (-4 * pi, 4 * pi)
grid = [80, 150]
return dic, srange, trange, grid

def Turritella():
"""
un autre modele
"""
'Omega': rad(-2), 'A': 22.2, 'a': 1.3, 'b': 1.5, 'P': 0, 'L': 0};
trange = (-30 * pi, 4 * pi)
grid = [30, 250]
return dic, srange, trange, grid

def Oxystele():
"""
"""
'Omega': rad(-2), 'A': 47, 'a': 40, 'b': 19, 'P': 0, 'L': 0,
'W1': 6, 'W2': 27, 'N': 8}
trange = (-20 * pi, 4 * pi)
grid = [40, 150]
return dic, srange, trange, grid

def Nautilus():
"""
"""
'a': 2, 'b': 1.5, 'P': 0, 'L': 0}
trange = (pi, 4 * pi)
grid = [30, 60]
return dic, srange, trange, grid

def Planorbis():
"""
"""
'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
trange = (-pi, 4 * pi)
grid = [40, 60]
return dic, srange, trange, grid

def Ammonite():
"""
"""
'P': 10, 'W1': 100, 'W2': 20, 'N': 15, 'L': 1/2}
trange = (-pi, 4 * pi)
grid = [40, 60]
return dic, srange, trange, grid

def Conus():
"""
"""
'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
trange = (-12 * pi, 4 * pi)
grid = [60, 80]
return dic, srange, trange, grid

def Helcion():
"""
"""
'A': 450, 'a': 400, 'b': 310, 'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
trange = (0, 4 * pi)
grid = [40, 60]
return dic, srange, trange, grid

def Codakia():
"""
"""
'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
trange = (-pi, 4 * pi)
grid = [40, 100]
return dic, srange, trange, grid

def NoName1():
"""
with bumps
"""
trange = (-pi, 3 * pi)
grid = [150, 150]
return dic, srange, trange, grid

def Strutholaria():
"""
"""
trange = (-8 * pi, 4 * pi)
grid = [150, 150]
return dic, srange, trange, grid

def shell(dic, srange, trange, grid):
"""
les variables parametriques sont s et t

EXAMPLES::

sage: P = shell(*Turritella())
sage: P.show(viewer='tachyon')
"""
# les parametres du modele
D = dic['D']
alpha = dic['alpha']
beta = dic['beta']
phi = dic['phi']
mu = dic['mu']
Omega = dic['Omega']
A = dic['A']
a = dic['a']
b = dic['b']
P = dic['P']
L = dic['L']
if 'W1' in dic:
W1 = dic['W1']
else:
W1 = 1
if 'W2' in dic:
W2 = dic['W2']
else:
W2 = 1
if 'N' in dic:
N = dic['N']
else:
N = 1

# les deux variables
t = var('t')
tmin, tmax = trange
s = var('s')
smin, smax = srange

# les formules
RE = lambda s: 1 / sqrt(cos(s)**2/a**2 + sin(s)**2/b**2)
g = lambda t: 2 * pi / N * (t * N / 2 / pi - round(t * N / 2 / pi))
R = lambda s, t: RE(s) + L*exp(-(2*(s-P)/W1)**2) * exp(-(2*g(t)/W2)**2)

cotalpha = cot(alpha)
Acbeta = A * cos(beta)
Asbeta = A * sin(beta)

x = lambda s, t: D*(Asbeta*cos(t)+R(s,t)*cos(s+phi)*cos(t+Omega)-R(s,t)*sin(mu)*sin(s+phi)*sin(t+Omega))*exp(t*cotalpha)
y = lambda s, t: (-Asbeta*sin(t)-R(s,t)*cos(s+phi)*sin(t+Omega)-R(s,t)*sin(mu)*sin(s+phi)*cos(t+Omega))*exp(t*cotalpha)
z = lambda s, t: (-Acbeta+R(s,t)*sin(s+phi)*cos(mu))*exp(t*cotalpha)

return parametric_plot3d([x, y, z], (s, smin, smax), (t, tmin, tmax),
plot_points=grid, aspect_ratio=[1, 1, 1],
color='orange')


Here is a translation of the code. Colors are not yet possible, see http://trac.sagemath.org/ticket/12212

"""
Code traduit depuis Maple, le code original est ici:

http://www.maplesoft.com/applications/view.aspx?SID=3851&view=html#mapleautobookmark9

REFERENCES:

A. Cortie : *Digital Seashells* Comput & Graphics Vol 17 , pp. 79-84 (1993)
"""
pi = float(pi)

"""
"""
return float(aa) / 360 * 2 * pi

def Natalina():
"""
un modele simple
"""
dic = {'D': 1,
'A': 25, 'a': 12, 'b': 16, 'P': 0, 'L': 0}
trange = (-2 * pi, 4 * pi)
grid = [100, 100]
return dic, srange, trange, grid

def Lyria():
"""
un autre modele
"""
'Omega': rad(-2), 'A':50, 'a':40, 'b':14, 'P':0, 'L':8,
trange = (-4 * pi, 4 * pi)
grid = [80, 150]
return dic, srange, trange, grid

def Turritella():
"""
un autre modele
"""
'Omega': rad(-2), 'A': 22.2, 'a': 1.3, 'b': 1.5, 'P': 0, 'L': 0};
trange = (-30 * pi, 4 * pi)
grid = [30, 250]
return dic, srange, trange, grid

def Oxystele():
"""
"""
'Omega': rad(-2), 'A': 47, 'a': 40, 'b': 19, 'P': 0, 'L': 0,
'W1': 6, 'W2': 27, 'N': 8}
trange = (-20 * pi, 4 * pi)
grid = [40, 150]
return dic, srange, trange, grid

def Nautilus():
"""
"""
'a': 2, 'b': 1.5, 'P': 0, 'L': 0}
trange = (pi, 4 * pi)
grid = [30, 60]
return dic, srange, trange, grid

def Planorbis():
"""
"""
'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
trange = (-pi, 4 * pi)
grid = [40, 60]
return dic, srange, trange, grid

def Ammonite():
"""
"""
'P': 10, 'W1': 100, 'W2': 20, 'N': 15, 'L': 1/2}
trange = (-pi, 4 * pi)
grid = [40, 60]
return dic, srange, trange, grid

def Conus():
"""
"""
'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
trange = (-12 * pi, 4 * pi)
grid = [60, 80]
return dic, srange, trange, grid

def Helcion():
"""
"""
'A': 450, 'a': 400, 'b': 310, 'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
trange = (0, 4 * pi)
grid = [40, 60]
return dic, srange, trange, grid

def Codakia():
"""
"""
'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
trange = (-pi, 4 * pi)
grid = [40, 100]
return dic, srange, trange, grid

def NoName1():
"""
with bumps
"""
trange = (-pi, 3 * pi)
grid = [150, 150]
return dic, srange, trange, grid

def Strutholaria():
"""
"""
trange = (-8 * pi, 4 * pi)
grid = [150, 150]
return dic, srange, trange, grid

def shell(dic, srange, trange, grid):
"""
les variables parametriques sont s et t

EXAMPLES::

sage: P = shell(*Turritella())
sage: P.show(viewer='tachyon')
"""
# les parametres du modele
D = dic['D']
alpha = dic['alpha']
beta = dic['beta']
phi = dic['phi']
mu = dic['mu']
Omega = dic['Omega']
A = dic['A']
a = dic['a']
b = dic['b']
P = dic['P']
L = dic['L']
if 'W1' in dic:
W1 = dic['W1']
else:
W1 = 1
if 'W2' in dic:
W2 = dic['W2']
else:
W2 = 1
if 'N' in dic:
N = dic['N']
else:
N = 1

# les deux variables
t = var('t')
tmin, tmax = trange
s = var('s')
smin, smax = srange

# les formules
round = floor(s + 0.5).function(s)
RE = lambda s: 1 (1 / sqrt(cos(s)**2/a**2 + sin(s)**2/b**2)
sin(s)**2/b**2)).function(s)
g = lambda t: 2 (2 * pi / N * (t * N / 2 / pi - round(t * N / 2 / pi))
pi))).function(t)
R = lambda s, t: RE(s) (RE(s) + L*exp(-(2*(s-P)/W1)**2) * exp(-(2*g(t)/W2)**2)
L*exp(-(2*(s-P)/W1)**2)
* exp(-(2*g(t)/W2)**2)).function(s,t)

cotalpha = cot(alpha)
Acbeta = A * cos(beta)
Asbeta = A * sin(beta)

x = lambda s, t: D*(Asbeta*cos(t)+R(s,t)*cos(s+phi)*cos(t+Omega)-R(s,t)*sin(mu)*sin(s+phi)*sin(t+Omega))*exp(t*cotalpha)
(D*(Asbeta*cos(t)+R(s,t)*cos(s+phi)*cos(t+Omega)-R(s,t)*sin(mu)*sin(s+phi)*sin(t+Omega))*exp(t*cotalpha)).function(s,t)
y = lambda s, t: (-Asbeta*sin(t)-R(s,t)*cos(s+phi)*sin(t+Omega)-R(s,t)*sin(mu)*sin(s+phi)*cos(t+Omega))*exp(t*cotalpha)
((-Asbeta*sin(t)-R(s,t)*cos(s+phi)*sin(t+Omega)-R(s,t)*sin(mu)*sin(s+phi)*cos(t+Omega))*exp(t*cotalpha)).function(s,t)
z = lambda s, t: (-Acbeta+R(s,t)*sin(s+phi)*cos(mu))*exp(t*cotalpha)
((-Acbeta+R(s,t)*sin(s+phi)*cos(mu))*exp(t*cotalpha)).function(s,t)

return parametric_plot3d([x, y, z], (s, smin, smax), (t, tmin, tmax),
plot_points=grid, aspect_ratio=[1, 1, 1],
color='orange')