~~META:date created=2010-04-18~~
{{tag>3d programmation python maya 3dsmax vray maths}}
====== Surfaces mathématiques ======
Génération des surfaces : Maya, Mel-Python. \\
Images : 3ds max, VRay.
{{gallery>..:galerie?500x500&surface*&reverse&showtitle}}
===Scripts===
Un tutoriel traitant de la génération de surfaces en python sous Maya est disponible ici : [[:articles:mel-python:surface_mathematique]].
##
# Klein bottle
# p01 2010
# Maya python script
##
from math import sin, cos, pi
from maya.cmds import curve, ls, loft, delete
rad = 1
uRes = .1
vRes = .1
cvs = []
u = -pi
while u <= pi :
pts = []
v = -pi
while v <= pi :
x = cos(u) * (rad + sin(v) * cos(u/2) - sin(2*v) * sin(u/2)/2)
y = sin(u) * (rad + sin(v) * cos(u/2) - sin(2*v) * sin(u/2)/2)
z = sin(u/2) * sin(v) + cos(u/2) * sin(2*v)/2
pts.append((x, y, z))
v += vRes
u += uRes
curve(p=pts)
cv = ls(sl=1)
cvs.append(cv[0])
loft(cvs)
delete(cvs)
##
# Heart surface
# p01 2010
# Maya python script
##
from math import sin, cos, pi, pow, sqrt, fabs
from maya.cmds import curve, ls, loft, delete
zRes = .1
tRes = .1
cut = 0.9
cvs = []
z = -cut
while z <= cut :
pts = []
t = -pi
while t <= pi :
r = 4 * sqrt(1 - z*z) * pow(sin(fabs(t)), fabs(t))
x = r * sin(t)
y = r * cos(t)
t += tRes
pts.append((x, y, z))
z += zRes
curve(p=pts)
cv = ls(sl=1)
cvs.append(cv[0])
loft(cvs)
delete(cvs)
##
# Dinis surface
# p01 2010
# Maya python script
##
from math import cos, sin, log, tan, pi
from maya.cmds import curve, ls, loft, delete
rad = 5
len = 1
laps = 3
inRad = 0.1
uRes = 0.3
vRes = 0.1
cvs = []
u = 0
while u <= laps*2*pi :
pts = []
v = 1.6
while v <= pi-inRad :
x = rad * cos(u) * sin(v)
y = rad * sin(u) * sin(v)
z = rad * (cos(v) + log(tan(v/2))) + len * u
pts.append((x, y, z))
v += vRes
u += uRes
curve(p=pts)
cv = ls(sl=1)
cvs.append(cv[0])
loft(cvs)
delete(cvs)
##
# Limpet torus
# p01 2010
# Maya python script
##
from math import sin, cos, pi, sqrt
from maya.cmds import curve, ls, loft, delete
width = 1
height = 1
length = 1
uRes = .3
vRes = .2
cvs = []
u = -pi
while u <= pi :
pts = []
v = -pi
while v <= pi :
x = cos(u) / (sqrt(width+1) + sin(v))
y = sin(u) / (sqrt(height+1) + sin(v))
z = (length+1) / (sqrt(length+1) + cos(v))
pts.append((x, y, z))
v += vRes
u += uRes
curve(p=pts)
cv = ls(sl=1)
cvs.append(cv[0])
loft(cvs, c=1)
delete(cvs)
##
# Pseudocatenoid
# p01 2010
# Maya python script
##
from math import sin, cos, tan, pi
from maya.cmds import curve, ls, loft, delete
uRes = .2
vRes = .2
cvs = []
u = 0
while u <= 2 * pi :
pts = []
v = -pi
while v <= pi :
x = cos(u) * (2 + cos(v))
y = sin(u) * (2 + cos(v))
z = x*x - y*y + 2 * x * y * tan(v)*tan(v)
pts.append((x, y, z))
v += vRes
u += uRes
curve(p=pts)
cv = ls(sl=1)
cvs.append(cv[0])
loft(cvs, c=1)
delete(cvs)
##
# Tractrix based surface
# p01 2010
# Maya python script
##
from math import cos, cosh, tanh, pi
from maya.cmds import curve, ls, loft, delete
uRes = .2
vRes = .2
cvs = []
u = 0
while u <= 2 * pi :
pts = []
v = -pi
while v <= pi :
x = cos(u) * (v - tanh(v))
y = cos(u) / cosh(v)
z = x*x - y*y + 2 * x * y * tanh(u)*tanh(u)
pts.append((x, y, z))
v += vRes
u += uRes
curve(p=pts)
cv = ls(sl=1)
cvs.append(cv[0])
loft(cvs, c=1)
delete(cvs)
##
# Triaxial hexatorus
# p01 2010
# Maya python script
##
from math import sin, cos, sqrt, pi
from maya.cmds import curve, ls, loft, delete
uRes = .2
vRes = .2
cvs = []
u = 0
while u <= 2 * pi :
pts = []
v = -pi
while v <= pi :
x = sin(u) / (sqrt(2) + cos(v))
y = sin(u+2*pi/3) / (sqrt(2) + cos(v+2*pi/3))
z = cos(u-2*pi/3) / (sqrt(2) + cos(v-2*pi/3))
pts.append((x, y, z))
v += vRes
u += uRes
curve(p=pts)
cv = ls(sl=1)
cvs.append(cv[0])
loft(cvs, c=1)
delete(cvs)