1 | initial version |
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)
def rad(aa):
"""
conversion degres -- radians
"""
return float(aa) / 360 * 2 * pi
def Natalina():
"""
un modele simple
"""
dic = {'D': 1,
'alpha': rad(80),
'beta': rad(40),
'phi': rad(55),
'mu': rad(10),
'Omega': rad(30),
'A': 25, 'a': 12, 'b': 16, 'P': 0, 'L': 0}
srange = (rad(-270), rad(80))
trange = (-2 * pi, 4 * pi)
grid = [100, 100]
return dic, srange, trange, grid
def Lyria():
"""
un autre modele
"""
dic = {'D': 1, 'alpha':rad(83.9), 'beta':rad(-19),
'phi': rad(45), 'mu':rad(1),
'Omega': rad(-2), 'A':50, 'a':40, 'b':14, 'P':0, 'L':8,
'W1': rad(6),
'W2': rad(27), 'N':8}
srange = (rad(-51), rad(9))
trange = (-4 * pi, 4 * pi)
grid = [80, 150]
return dic, srange, trange, grid
def Turritella():
"""
un autre modele
"""
dic = {'D': 1, 'alpha': rad(88.9), 'beta': rad(4), 'phi': rad(55),
'mu': rad(1),
'Omega': rad(-2), 'A': 22.2, 'a': 1.3, 'b': 1.5, 'P': 0, 'L': 0};
srange = (rad(-267), rad(39))
trange = (-30 * pi, 4 * pi)
grid = [30, 250]
return dic, srange, trange, grid
def Oxystele():
"""
"""
dic = {'D': 1, 'alpha': rad(84.9), 'beta': rad(7), 'phi': rad(-36),
'mu': rad(1),
'Omega': rad(-2), 'A': 47, 'a': 40, 'b': 19, 'P': 0, 'L': 0,
'W1': 6, 'W2': 27, 'N': 8}
srange = (rad(-70),rad(70))
trange = (-20 * pi, 4 * pi)
grid = [40, 150]
return dic, srange, trange, grid
def Nautilus():
"""
"""
dic = {'D': 1, 'alpha': rad(80), 'beta': rad(90), 'phi': rad(0),
'mu': rad(0), 'Omega': rad(0), 'A': 2,
'a': 2, 'b': 1.5, 'P': 0, 'L': 0}
srange = (rad(-163),rad(163))
trange = (pi, 4 * pi)
grid = [30, 60]
return dic, srange, trange, grid
def Planorbis():
"""
"""
dic = {'D': 1, 'alpha': rad(84), 'beta': rad(85), 'phi': rad(10),
'mu': rad(45), 'Omega': rad(5) , 'A': 45, 'a': 20, 'b': 30,
'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
srange = (rad(-150), rad(130))
trange = (-pi, 4 * pi)
grid = [40, 60]
return dic, srange, trange, grid
def Ammonite():
"""
"""
dic = {'D': 1, 'alpha': rad(83), 'beta': rad(90), 'phi': rad(1),
'mu': rad(1), 'Omega': rad(1), 'A': 2.5, 'a': 1, 'b': 0.9,
'P': 10, 'W1': 100, 'W2': 20, 'N': 15, 'L': 1/2}
srange = (rad(-170), rad(170))
trange = (-pi, 4 * pi)
grid = [40, 60]
return dic, srange, trange, grid
def Conus():
"""
"""
dic = {'D': 1, 'alpha': rad(87), 'beta': rad(7), 'phi': rad(78),
'mu': rad(0), 'Omega': rad(0), 'A': 7, 'a': 4.3, 'b': 1,
'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
srange = (rad(-180),rad(2))
trange = (-12 * pi, 4 * pi)
grid = [60, 80]
return dic, srange, trange, grid
def Helcion():
"""
"""
dic = {'D': 1, 'alpha': rad(18), 'beta': rad(90), 'phi': rad(0),
'mu': rad(0), 'Omega': rad(-40),
'A': 450, 'a': 400, 'b': 310, 'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
srange = (rad(-180), rad(180))
trange = (0, 4 * pi)
grid = [40, 60]
return dic, srange, trange, grid
def Codakia():
"""
"""
dic = {'D': 1, 'alpha': rad(37), 'beta': rad(90), 'phi': rad(0),
'mu': rad(1), 'Omega': rad(1), 'A': 10500, 'a': 10000, 'b': 10500,
'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
srange = (rad(-180), rad(180))
trange = (-pi, 4 * pi)
grid = [40, 100]
return dic, srange, trange, grid
def NoName1():
"""
with bumps
"""
dic = {'D': 1, 'alpha': rad(83), 'beta': rad(90), 'phi': rad(1),
'mu': rad(1), 'Omega': rad(1), 'A': 2.5, 'a': 1, 'b': 0.9,
'W1': rad(100), 'W2': rad(20), 'N': 15, 'L': 1/2, 'P': rad(10)}
srange = (rad(-170), rad(170))
trange = (-pi, 3 * pi)
grid = [150, 150]
return dic, srange, trange, grid
def Strutholaria():
"""
"""
dic = {'D': 1, 'alpha': rad(86.9), 'beta': rad(13), 'phi': rad(40),
'mu': rad(10), 'Omega': rad(30), 'A': 5, 'a': 1.8, 'b': 1.6,
'P': rad(-15), 'L': 1/2, 'W1': rad(5), 'W2': rad(5), 'N': 16}
srange = (rad(-168), rad(24))
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')
2 | No.2 Revision |
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)
def rad(aa):
"""
conversion degres -- radians
"""
return float(aa) / 360 * 2 * pi
def Natalina():
"""
un modele simple
"""
dic = {'D': 1,
'alpha': rad(80),
'beta': rad(40),
'phi': rad(55),
'mu': rad(10),
'Omega': rad(30),
'A': 25, 'a': 12, 'b': 16, 'P': 0, 'L': 0}
srange = (rad(-270), rad(80))
trange = (-2 * pi, 4 * pi)
grid = [100, 100]
return dic, srange, trange, grid
def Lyria():
"""
un autre modele
"""
dic = {'D': 1, 'alpha':rad(83.9), 'beta':rad(-19),
'phi': rad(45), 'mu':rad(1),
'Omega': rad(-2), 'A':50, 'a':40, 'b':14, 'P':0, 'L':8,
'W1': rad(6),
'W2': rad(27), 'N':8}
srange = (rad(-51), rad(9))
trange = (-4 * pi, 4 * pi)
grid = [80, 150]
return dic, srange, trange, grid
def Turritella():
"""
un autre modele
"""
dic = {'D': 1, 'alpha': rad(88.9), 'beta': rad(4), 'phi': rad(55),
'mu': rad(1),
'Omega': rad(-2), 'A': 22.2, 'a': 1.3, 'b': 1.5, 'P': 0, 'L': 0};
srange = (rad(-267), rad(39))
trange = (-30 * pi, 4 * pi)
grid = [30, 250]
return dic, srange, trange, grid
def Oxystele():
"""
"""
dic = {'D': 1, 'alpha': rad(84.9), 'beta': rad(7), 'phi': rad(-36),
'mu': rad(1),
'Omega': rad(-2), 'A': 47, 'a': 40, 'b': 19, 'P': 0, 'L': 0,
'W1': 6, 'W2': 27, 'N': 8}
srange = (rad(-70),rad(70))
trange = (-20 * pi, 4 * pi)
grid = [40, 150]
return dic, srange, trange, grid
def Nautilus():
"""
"""
dic = {'D': 1, 'alpha': rad(80), 'beta': rad(90), 'phi': rad(0),
'mu': rad(0), 'Omega': rad(0), 'A': 2,
'a': 2, 'b': 1.5, 'P': 0, 'L': 0}
srange = (rad(-163),rad(163))
trange = (pi, 4 * pi)
grid = [30, 60]
return dic, srange, trange, grid
def Planorbis():
"""
"""
dic = {'D': 1, 'alpha': rad(84), 'beta': rad(85), 'phi': rad(10),
'mu': rad(45), 'Omega': rad(5) , 'A': 45, 'a': 20, 'b': 30,
'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
srange = (rad(-150), rad(130))
trange = (-pi, 4 * pi)
grid = [40, 60]
return dic, srange, trange, grid
def Ammonite():
"""
"""
dic = {'D': 1, 'alpha': rad(83), 'beta': rad(90), 'phi': rad(1),
'mu': rad(1), 'Omega': rad(1), 'A': 2.5, 'a': 1, 'b': 0.9,
'P': 10, 'W1': 100, 'W2': 20, 'N': 15, 'L': 1/2}
srange = (rad(-170), rad(170))
trange = (-pi, 4 * pi)
grid = [40, 60]
return dic, srange, trange, grid
def Conus():
"""
"""
dic = {'D': 1, 'alpha': rad(87), 'beta': rad(7), 'phi': rad(78),
'mu': rad(0), 'Omega': rad(0), 'A': 7, 'a': 4.3, 'b': 1,
'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
srange = (rad(-180),rad(2))
trange = (-12 * pi, 4 * pi)
grid = [60, 80]
return dic, srange, trange, grid
def Helcion():
"""
"""
dic = {'D': 1, 'alpha': rad(18), 'beta': rad(90), 'phi': rad(0),
'mu': rad(0), 'Omega': rad(-40),
'A': 450, 'a': 400, 'b': 310, 'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
srange = (rad(-180), rad(180))
trange = (0, 4 * pi)
grid = [40, 60]
return dic, srange, trange, grid
def Codakia():
"""
"""
dic = {'D': 1, 'alpha': rad(37), 'beta': rad(90), 'phi': rad(0),
'mu': rad(1), 'Omega': rad(1), 'A': 10500, 'a': 10000, 'b': 10500,
'P': 0, 'L': 0, 'W1': 6, 'W2': 27, 'N': 8}
srange = (rad(-180), rad(180))
trange = (-pi, 4 * pi)
grid = [40, 100]
return dic, srange, trange, grid
def NoName1():
"""
with bumps
"""
dic = {'D': 1, 'alpha': rad(83), 'beta': rad(90), 'phi': rad(1),
'mu': rad(1), 'Omega': rad(1), 'A': 2.5, 'a': 1, 'b': 0.9,
'W1': rad(100), 'W2': rad(20), 'N': 15, 'L': 1/2, 'P': rad(10)}
srange = (rad(-170), rad(170))
trange = (-pi, 3 * pi)
grid = [150, 150]
return dic, srange, trange, grid
def Strutholaria():
"""
"""
dic = {'D': 1, 'alpha': rad(86.9), 'beta': rad(13), 'phi': rad(40),
'mu': rad(10), 'Omega': rad(30), 'A': 5, 'a': 1.8, 'b': 1.6,
'P': rad(-15), 'L': 1/2, 'W1': rad(5), 'W2': rad(5), 'N': 16}
srange = (rad(-168), rad(24))
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')