def __init__(self): super(Catenoide, self).__init__( u"Cortamos una catenoide para obtener parte de una helicoide") self.camera_position = (8.2, 8.2, 8.2) self.camera_viewAll = False def param(u, v, t): t2 = pi / 2 - t x = cos(t2) * sinh(v) * sin(u) + sin(t2) * cosh(v) * cos(u) y = -cos(t2) * sinh(v) * cos(u) + sin(t2) * cosh(v) * sin(u) z = u * cos(t2) + v * sin(t2) return x, y, z cat = ParametricPlot3D(param, (-pi, pi, 60), (-2, 2)) ht = cat.getParameter('t') ht.timeline.setDuration(3000) ht.updateRange((0, pi / 2, 0)) cat.setVerticesPerColumn(2) cat.setAmbientColor(_1(4, 73, 143)) cat.setDiffuseColor(_1(4, 73, 143)) cat.setSpecularColor(_1(4, 73, 143)) s = Slider(rangep=('z', 2, 60, 2, 59), func=cat.setVerticesPerColumn, duration=3000, parent=self) self.addChild(cat) params = [s, ht] ## no queremos los controles for p in params: p.hide() anims = [p.asAnimation() for p in params] self.setupAnimations(anims)
def __init__(self): super(Helicoide, self).__init__( u"Isometría local entre una helicoide y una catenoide") self.camera_position = (8.2, 8.2, 8.2) self.camera_viewAll = False def param(u, v, t): x = cos(t) * sinh(v) * sin(u) + sin(t) * cosh(v) * cos(u) y = -cos(t) * sinh(v) * cos(u) + sin(t) * cosh(v) * sin(u) z = u * cos(t) + v * sin(t) return x, y, z helic1 = ParametricPlot3D(param, (-pi, pi, 60), (-2, 2)) ht = helic1.getParameter('t') ht.timeline.setDuration(3000) ht.updateRange((0, pi / 2, 0)) helic1.setVerticesPerColumn(2) helic1.setAmbientColor(_1(202, 78, 70)) helic1.setDiffuseColor(_1(202, 78, 70)) helic1.setSpecularColor(_1(202, 78, 70)) s = Slider(rangep=('z', 2, 60, 2, 59), func=helic1.setVerticesPerColumn, duration=3000, parent=self) self.addChild(helic1) params = [s, ht] ## no queremos los controles for p in params: p.hide() anims = [p.asAnimation() for p in params] self.setupAnimations(anims)
def __init__(self): "F(x,y) = (x, y, x + y - 6)" #u"""l plano x + y + z - 2.5 = 0""" Page.__init__(self, u"Plano<br><br>F(x,y) = (x, y, x + y - 6)") plane = lambda x, y: -x - y p1 = lambda x, y, t1: (x, y, (1 - t1) * (-x - y) - 2 * t1) p2 = lambda x, y, t2: (x, (1 - t2) * y - 2 * t2, -x - y) p3 = lambda x, y, t3: ((1 - t3) * x - 2 * t3, y, -x - y) r = (-1, 1, 15) plano = Plot3D(plane, (-1, 1), (-1, 1)) plano.setTransparencyType(8) plano1 = ParametricPlot3D(p1, r, r) plano2 = ParametricPlot3D(p2, r, r) plano3 = ParametricPlot3D(p3, r, r) planos = [plano1, plano2, plano3] for p in planos: p.linesVisible = True p.meshVisible = False plano1.setMeshDiffuseColor((1, 0, 0)) plano2.setMeshDiffuseColor((0, 1, 0)) plano3.setMeshDiffuseColor((0, 1, 1)) plano.diffuseColor = _1(29, 214, 216) plano.transparency = 0.5 plano.setAmbientColor(_1(29, 214 , 216)) self.setupPlanes((-2, 2, 7)) self.addChildren([plano, plano1, plano2, plano3]) ## no controls for i, plano in enumerate(planos): plano.parameters['t%d' % (i + 1)].hide() self.setupAnimations([plano.parameters['t%d' % (i + 1)].asAnimation() for i, plano in enumerate(planos)])
def __init__(self): super(Catenoide, self).__init__(u"Cortamos una catenoide para obtener parte de una helicoide") self.camera_position = (8.2, 8.2, 8.2) self.camera_viewAll = False def param(u, v, t): t2 = pi / 2 - t x = cos(t2) * sinh(v) * sin(u) + sin(t2) * cosh(v) * cos(u) y = -cos(t2) * sinh(v) * cos(u) + sin(t2) * cosh(v) * sin(u) z = u * cos(t2) + v * sin(t2) return x, y, z cat = ParametricPlot3D(param, (-pi, pi, 60), (-2, 2)) ht = cat.getParameter("t") ht.timeline.setDuration(3000) ht.updateRange((0, pi / 2, 0)) cat.setVerticesPerColumn(2) cat.setAmbientColor(_1(4, 73, 143)) cat.setDiffuseColor(_1(4, 73, 143)) cat.setSpecularColor(_1(4, 73, 143)) s = Slider(rangep=("z", 2, 60, 2, 59), func=cat.setVerticesPerColumn, duration=3000, parent=self) self.addChild(cat) params = [s, ht] ## no queremos los controles for p in params: p.hide() anims = [p.asAnimation() for p in params] self.setupAnimations(anims)
def __init__(self): """F(x,y)=x^2 + y^2 - z = 0""" Page.__init__(self, u"Paraboloide Elíptico<br><br>F(x,y)=(x, y, x<sup>2</sup>/a<sup>2</sup> + y<sup>2</sup>/b<sup>2</sup>)") z = 0.5 par = RevolutionPlot3D(lambda r, t: r ** 2 + z, (0, 1.42), (0, 2 * pi)) x, y, z2, u, v, cose, sen, t = createVars(['x', 'y', 'z', 'u', 'v', 'cos', 'sen', 't']) mesh1 = Plot3D(lambda x, y, h: h * (x ** 2 + y ** 2 + z - .01), (-1, 1), (-1, 1)) #mesh1.addEqn(x**2+y**2 - z2**2 == 1) mesh1.addFunction(lambda x, y, h: h * (x ** 2 + y ** 2 + z + .01)) mesh1.setLinesVisible(True) mesh1.setMeshVisible(False) mesh1.setBoundingBox(zrange=(-1, 3.0)) par.setAmbientColor(_1(145, 61, 74)) par.setDiffuseColor(_1(145, 61, 74)) par.setSpecularColor(_1(145, 61, 74)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(par) self.addChild(mesh1) self.addChild(baseplane)
def __init__(self): """F(x,y)=x^2 + y^2 - z = 0""" Page.__init__( self, u"Paraboloide Elíptico<br><br>F(x,y)=(x, y, x<sup>2</sup>/a<sup>2</sup> + y<sup>2</sup>/b<sup>2</sup>)" ) z = 0.5 par = RevolutionPlot3D(lambda r, t: r**2 + z, (0, 1), (0, 2 * pi)) x, y, z2, u, v, cose, sen, t = createVars( ['x', 'y', 'z', 'u', 'v', 'cos', 'sen', 't']) mesh1 = Plot3D(lambda x, y, h: h * (x**2 + y**2 + z - .01), (-1, 1), (-1, 1)) mesh1.addEqn(x**2 + y**2 - z2**2 == 1) mesh1.addFunction(lambda x, y, h: h * (x**2 + y**2 + z + .01)) mesh1.setLinesVisible(True) mesh1.setMeshVisible(False) mesh1.setBoundingBox(zrange=(-1, 1.5)) par.setAmbientColor(_1(145, 61, 74)) par.setDiffuseColor(_1(145, 61, 74)) par.setSpecularColor(_1(145, 61, 74)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(par) self.addChild(mesh1) self.addChild(baseplane)
def __init__(self): super(Helicoide, self).__init__(u"Isometría local entre una helicoide y una catenoide") self.camera_position = (8.2, 8.2, 8.2) self.camera_viewAll = False def param(u, v, t): x = cos(t) * sinh(v) * sin(u) + sin(t) * cosh(v) * cos(u) y = -cos(t) * sinh(v) * cos(u) + sin(t) * cosh(v) * sin(u) z = u * cos(t) + v * sin(t) return x, y, z helic1 = ParametricPlot3D(param, (-pi, pi, 60), (-2, 2)) ht = helic1.getParameter("t") ht.timeline.setDuration(3000) ht.updateRange((0, pi / 2, 0)) helic1.setVerticesPerColumn(2) helic1.setAmbientColor(_1(202, 78, 70)) helic1.setDiffuseColor(_1(202, 78, 70)) helic1.setSpecularColor(_1(202, 78, 70)) s = Slider(rangep=("z", 2, 60, 2, 59), func=helic1.setVerticesPerColumn, duration=3000, parent=self) self.addChild(helic1) params = [s, ht] ## no queremos los controles for p in params: p.hide() anims = [p.asAnimation() for p in params] self.setupAnimations(anims)
def __init__(self): Page.__init__(self, u"Hélice circular, curvatura y torsión<br><br>(cos s/√2, sen s/√2, s/√2)") self.camera_position = (10, -10, 10) self.showAxis(False) tmin = -2 * pi tmax = 2 * pi npuntos = 300 self.addChild(Cylinder(_1(185, 46, 61), tmax - tmin, 2)) ## ============================================ # 1 implica primer derivada, 2 implica segunda derivada def param1hc(t): return 2*Vec3(cos(t), sin(t), t/3.0) def param2hc(t): return 2*Vec3(-sin(t), cos(t), 1/3.0) def param3hc(t): return 2*Vec3(-cos(t), -sin(t), 0) def param4hc(t): return 2*Vec3(sin(t)/3.0, -cos(t)/3.0, 1.0) espiral = Curve3D(param1hc, (tmin*1.5, tmax*1.5, npuntos), color=_1(255, 255, 255)) tangente = espiral.attachField("tangente", param2hc).setLengthFactor(1).setWidthFactor(.6) tangente.setRadius( 0.06 ) tangente.setDiffuseColor( _1(20,240,20) ) normal = espiral.attachField("normal", param3hc).setLengthFactor(1).setWidthFactor(.6) normal.setRadius( 0.06 ) normal.setDiffuseColor( _1(240,120,20) ) binormal = espiral.attachField("binormal", param4hc).setLengthFactor(1).setWidthFactor(.6) binormal.setRadius( 0.06 ) binormal.setDiffuseColor( _1(20,120,240) ) self.addChild(espiral) self.setupAnimations([ AnimationGroup([tangente, normal, binormal], (10000,0,len(espiral)-1)) ])
def __init__(self): "x^4 + 2x^2y^2 + y^4 -z = 0" Page.__init__( self, u"Superficie cuártica<br><br>F(x,y)=(x,y,x<sup>4</sup>+2x<sup>2</sup>y<sup>2</sup>+y<sup>4</sup>)" ) # cuart = Plot3D(lambda x,y: x**4 + 2*x**2*y**2 + y**4 + 1, (-1,1),(-1,1)) cuart = RevolutionPlot3D(lambda r, t: r**4 + 1, (0, 1), (0, 2 * pi)) # cuart.setScaleFactor((1,1,.6)) mesh1 = Plot3D(lambda x, y, h: h * (x**4 + 2 * x**2 * y**2 + y**4 + 1), (-1, 1), (-1, 1)) mesh1.setLinesVisible(True) mesh1.setMeshVisible(False) mesh1.setBoundingBox(zrange=(-1, 2)) # cuart.setAmbientColor(_1(168,211,8)) cuart.setDiffuseColor(_1(168, 211, 8)) cuart.setSpecularColor(_1(168, 211, 8)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(cuart) self.addChild(mesh1) self.addChild(baseplane)
def __init__(self): Page.__init__(self, u"Planos osculador, normal y rectificante") tmin = -2 * pi tmax = 2 * pi ## ============================================ sq2 = 2 ** 0.5 inv_sq2 = (1. / sq2) def helix(s): s_times_sq2 = inv_sq2 * s return Vec3(cos(s_times_sq2), sin(s_times_sq2), s_times_sq2) def tangent(s): s_div_sq2 = s / sq2 return Vec3(-inv_sq2 * sin(s_div_sq2), inv_sq2 * cos(s_div_sq2), inv_sq2) def normal(s): s_div_sq2 = s / sq2 return Vec3(-cos(s_div_sq2), -sin(s_div_sq2), 0) def bi_normal(s): s_div_sq2 = s / sq2 return Vec3(inv_sq2 * sin(s_div_sq2), -inv_sq2 * cos(s_div_sq2), inv_sq2) curve = Curve3D(helix, (tmin, tmax, 100), _1(206, 75, 150), 2) self.addChild(curve) #======================================================================= # Vectors #======================================================================= field_tangent = curve.attachField("tangent", tangent).show() field_normal = curve.attachField("normal", normal).show() field_binormal = curve.attachField("binormal", bi_normal).show() field_tangent.setDiffuseColor( _1(255, 0, 0) ) field_normal.setDiffuseColor( _1(255, 255, 0) ) field_binormal.setDiffuseColor( _1(0, 0, 255) ) #======================================================================= # Planes #======================================================================= def get_points(v1, v2): return v2.p1, v1.p2, v2.p2 color = (.5, .5, .5) plane_osculating = Plane(color, *get_points(field_tangent, field_normal)) plane_normal = Plane(color, *get_points(field_normal, field_binormal)) plane_rectifying = Plane(color, *get_points(field_binormal, field_tangent)) self.addChildren([plane_osculating, plane_normal, plane_rectifying]) def update_planes(n): plane_osculating.setPoints(*get_points(field_tangent, field_normal)) plane_normal.setPoints(*get_points(field_normal, field_binormal)) plane_rectifying.setPoints(*get_points(field_binormal, field_tangent)) r = (5000, 0, len(curve) - 1) animation = Animatable(update_planes, r) self.setupAnimations([ AnimationGroup([field_tangent, field_normal, field_binormal, animation], r) ])
def __init__(self): u"""^2 + y^2 = z^2""" Page.__init__(self, u"Esfera, parametrización por proyecciones estereográficas") r = .998 esf = ParametricPlot3D(lambda t, f: (r * sin(t) * cos(f), r * sin(t) * sin(f), r * cos(t)), (0, pi, 70), (0, 2 * pi, 70)) # esf.setAmbientColor(_1(99,136,63)) esf.setDiffuseColor(_1(99, 136, 63)) esf.setSpecularColor(_1(99, 136, 63)) def proyZm1(u, v, t1): """proy desde el polo norte al plano z=-1""" den = u ** 2 + v ** 2 + 4 x = u - t1 * (u - 4 * u / den) y = v - t1 * (v - 4 * v / den) z = -1 - t1 * (-2 + 8 / den) return (x, y, z) def proyZ1(u, v, t2): """proy desde el polo sur al plano z=1""" den = u ** 2 + v ** 2 + 4 x = u - t2 * (u - 4 * u / den) y = v - t2 * (v - 4 * v / den) z = 1 - t2 * (2 - 8 / den) return (x, y, z) stereo = ParametricPlot3D(proyZm1, (-3, 3, 70), (-3, 3, 70)) stereo.setLinesVisible(True) stereo.setMeshVisible(False) stereo.setMeshDiffuseColor(_1(117, 55, 79)) stereo2 = ParametricPlot3D(proyZ1, (-3, 3, 70), (-3, 3, 70)) stereo2.setLinesVisible(True) stereo2.setMeshVisible(False) stereo2.setMeshDiffuseColor(_1(80, 87, 193)) stereo2.setTransparency(0.5) stereo2.setTransparencyType(8) baseplane = BasePlane() baseplane.setHeight(-1.005) baseplane.setRange((-4, 4, 7)) self.addChild(esf) self.addChild(stereo2) self.addChild(stereo) self.addChild(baseplane) params = [stereo,stereo2] ## no queremos los controles for i,p in enumerate(params): p.parameters['t%d' % (i+1)].hide() anims = [p.parameters['t%d' % (i+1)].asAnimation() for i,p in enumerate(params)] self.setupAnimations(anims)
def __init__(self): Page.__init__(self, u"Campo con un ciclo límite en el plano") par_plano = lambda u, v: Vec3(u,v,0) def plano_u(u,v): return Vec3(1,0,0) def plano_v(u,v): return Vec3(0,1,0) parab = ParametricPlot3D(par_plano, (-3,3,20),(-3,3,20)) parab.setTransparency(0.4) parab.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) # Esta familia de curvas NO es solucion de un sistema de ecuaciones # diferenciales de orden 1 (se intersectan)... # pero se parece a la solucion del sistema presentado def make_curva(c): return lambda t: Vec3( e**(-(c*t+c))*cos(t), e**(-(c*t+c))*sin(t), 0.02 ) def make_tang(c): return lambda t: Vec3( -c*e**(-(c*t+c))*cos(t) - e**(-(c*t+c))*sin(t), -c*e**(-(c*t+c))*sin(t) + e**(-(c*t+c))*cos(t), 0.02 ) tangentes = [] ncurves = 7 steps = 80 for c in range(0,ncurves): ## -1 < ct < 1 ct = c/20.0 - float(ncurves-1)/40.0 curva = Curve3D(make_curva(ct),(0,2*pi,steps), width=1) if ct == 0: curva = Curve3D(make_curva(ct),(0,2*pi,steps), width=1, color=_1(20, 240, 40)) curva.attachField("tangente", make_tang(ct)).setLengthFactor(.5).setWidthFactor(.25).add_tail(0.025) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (6000, 0, steps-1)) self.setupAnimations([a1]) critic = Sphere( center=Vec3(0,0,0), radius=0.025, color=_1(240,10,20) ) self.addChild(critic)
def __init__(self): Page.__init__(self, u"Elipsoide<br><br>x<sup>2</sup>/a<sup>2</sup> + y<sup>2</sup>/b<sup>2</sup> + z<sup>2</sup>/c<sup>2</sup> = 1") param = lambda u,v: (cos(u)*cos(v), 1.5*cos(v)*sin(u), 2*sin(v)) elipsoide = ParametricPlot3D(param, (-pi, pi), (-pi/2,pi/2)) col = _1(84,129,121) elipsoide.setAmbientColor(col).setDiffuseColor(col).setSpecularColor(col) par1 = lambda u,v: Vec3(-sin(u)*cos(v), 1.5*cos(u)*cos(v), 0) par2 = lambda u,v: Vec3(-cos(u)*sin(v), -1.5*sin(u)*sin(v), 2*cos(v)) tp = TangentPlane2(param,par1,par2,(0,0),_1(252,250,225)) self.addChild(elipsoide) self.addChild(tp) Slider(rangep=('u', -pi,pi,0,20),func=tp.setU, duration=8000, parent=self) Slider(rangep=('v', -pi/2,pi/2,0,20),func=tp.setV, duration=8000, parent=self)
def __init__(self): Page.__init__(self, u"Elipsoide") param = lambda u,v: (cos(u)*cos(v), 1.5*cos(v)*sin(u), 2*sin(v)) elipsoide = ParametricPlot3D(param, (-pi, pi), (-pi/2,pi/2)) col = _1(84,129,121) elipsoide.setAmbientColor(col).setDiffuseColor(col).setSpecularColor(col) par1 = lambda u,v: Vec3(-sin(u)*cos(v), 1.5*cos(u)*cos(v), 0) par2 = lambda u,v: Vec3(-cos(u)*sin(v), -1.5*sin(u)*sin(v), 2*cos(v)) tp = TangentPlane2(param,par1,par2,(0,0),_1(252,250,225)) self.addChild(elipsoide) self.addChild(tp) Slider(rangep=('u', -pi,pi,0,20),func=tp.setU, parent=self) Slider(rangep=('v', -pi/2,pi/2,0,20),func=tp.setV,parent=self)
def __init__(self): #u"""x^2 + y^2 + z^2 = 1""" super(EsferaCasquetes, self).__init__(u"Otro atlas de la esfera") r = .998 esf = ParametricPlot3D( lambda t, f: (r * sin(t) * cos(f), r * sin(t) * sin(f), r * cos(t)), (0, pi, 70), (0, 2 * pi, 70)) esf.setDiffuseColor(_1(99, 136, 63)) esf.setSpecularColor(_1(99, 136, 63)) pars = [ lambda u, v, t1: (u, v, 1.5 - t1 * (1.5 - sqrt(1 - u**2 - v**2))), lambda u, v, t2: (u, v, -1 - t2 * (-1 + sqrt(1 - u**2 - v**2))), lambda u, v, t3: (u, 1.5 - t3 * (1.5 - sqrt(1 - u**2 - v**2)), v), lambda u, v, t4: (u, -1.5 - t4 * (-1.5 + sqrt(1 - u**2 - v**2)), v), lambda u, v, t5: (1.5 - t5 * (1.5 - sqrt(1 - u**2 - v**2)), u, v), lambda u, v, t6, : (-1.5 - t6 * (-1.5 + sqrt(1 - u**2 - v**2)), u, v) ] d = .7 colores = [(0, 0, 1), (0, 0, 1), (0, 1, 0), (0, 1, 0), (1, 0, 0), (1, 0, 0)] planos = [ ParametricPlot3D(par, (-d, d, 40), (-d, d, 40)).setLinesVisible( True).setMeshVisible(False).setMeshDiffuseColor(colores[i]) for i, par in enumerate(pars) ] baseplane = BasePlane() baseplane.setHeight(-1.005) baseplane.setRange((-2, 2, 7)) self.addChild(esf) for p in planos: self.addChild(p) self.addChild(baseplane) ## no queremos los controles for i, plano in enumerate(planos): plano.parameters['t%d' % (i + 1)].hide() anims = [ plano.parameters['t%d' % (i + 1)].asAnimation() for i, plano in enumerate(planos) ] self.setupAnimations(anims)
def __init__(self): Page.__init__(self, u"Cilindro<br><br>x<sup>2</sup>/a<sup>2</sup> + y<sup>2</sup>/b<sup>2</sup> = 1") param = lambda u,t: Vec3(cos(u),sin(u),t) cilindro = ParametricPlot3D(param, (0, 2*pi), (-1,1)) col = _1(177,89,77) cilindro.setAmbientColor(col).setDiffuseColor(col).setSpecularColor(col) def par1(u,t): return Vec3(-sin(u),cos(u),0) def par2(u,t): return Vec3(0,0,1) tp = TangentPlane2(param,par1,par2,(0,0),_1(252,250,225)) tp.localOriginSphere.hide() tp.localYAxis.setColor(col).setWidth(2).show() Slider(rangep=('u', 0,2*pi,0,20),func=tp.setU, duration=8000, parent=self) Slider(rangep=('t', -1,1,0,20),func=tp.setV, duration=4000, parent=self) self.addChild(cilindro) self.addChild(tp)
def __init__(self): Page.__init__(self, u"Otro campo en la esfera con dos singularidades") par_esfera = lambda u, v: Vec3(sin(u) * cos(v), sin(u) * sin(v), cos(u)) def esfera_u(u,v): return Vec3(-cos(u)*cos(v)*sin(u), -cos(u)*sin(u)*sin(v), 1-cos(u)**2) parab = ParametricPlot3D(par_esfera, (0,pi,150),(0,2*pi,100)) parab.setTransparency(0.4) parab.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): return lambda t: par_esfera(t,c) def make_tang(c): return lambda t: esfera_u(t,c) tangentes = [] curves = [] ncurves = 70 for c in range(0,ncurves+1): ## -1 < ct < 1 ct = c/float(ncurves) * 2*pi curve = Curve3D(make_curva(ct),(-(pi-.02),-.02,100), width=1) tangent = curve.attachField("tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1).show() tangentes.append(tangent) curves.append(curve) self.addChildren(curves) self.setupAnimations([AnimationGroup(tangentes, (6000, 0, 99))])
def __init__(self): super(Mobius, self).__init__(u"No orientabilidad de la Banda de Möbius") # self.camera_position = (3.0, 2.8, 2.8) def par(u, v): return cos(u) + v * cos(u / 2) * cos(u), sin(u) + v * cos( u / 2) * sin(u), v * sin(u / 2) mobius = ParametricPlot3D(par, (-pi, pi, 60), (-.5, .5, 14)) mobius.setTransparency(0.5) def curva(t): return par(t, 0) def puntos(u): return Vec3( cos(u) * sin(u / 2.0), sin(u / 2.0) * sin(u), -cos(u / 2.0)) cm = Curve3D(curva, (-pi, pi, 200), color=_1(255, 255, 255), width=3) aceleracion_cm = cm.attachField( "aceleracion", puntos).setLengthFactor(1).setWidthFactor(.5) aceleracion_cm.animation.setDuration(12000) self.addChild(mobius) self.addChild(cm) self.addChild(Arrow((-1, 0, 0), (0, 0, 0), 0.02)) self.setupAnimations([aceleracion_cm])
def __init__(self): super(Mobius, self).__init__(u"No orientabilidad de la Banda de Möbius") # self.camera_position = (3.0, 2.8, 2.8) def par(u, v): return cos(u) + v * cos(u / 2) * cos(u), sin(u) + v * cos(u / 2) * sin(u), v * sin(u / 2) mobius = ParametricPlot3D(par, (-pi, pi, 60), (-0.5, 0.5, 14)) mobius.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) mobius.setTransparency(0.2) def curva(t): # return par(t,0.0) p = par(t, 0.0) return (0.98 * p[0], 0.98 * p[1], 0.0) def puntos(u): return Vec3(cos(u) * sin(u / 2.0), sin(u / 2.0) * sin(u), -cos(u / 2.0)) cm = Curve3D(curva, (-pi, pi, 200), color=_1(255, 255, 255), width=3) aceleracion_cm = cm.attachField("aceleracion", puntos).setLengthFactor(1).setWidthFactor(0.5) aceleracion_cm.animation.setDuration(12000) self.addChild(mobius) self.addChild(cm) self.addChild(Arrow((-1, 0, 0), (0, 0, 0), 0.02)) self.setupAnimations([aceleracion_cm])
def __init__(self): Page.__init__(self, u"Cilindro") param = lambda u,t: Vec3(cos(u),sin(u),t) cilindro = ParametricPlot3D(param, (0, 2*pi), (-1,1)) col = _1(177,89,77) cilindro.setAmbientColor(col).setDiffuseColor(col).setSpecularColor(col) def par1(u,t): return Vec3(-sin(u),cos(u),0) def par2(u,t): return Vec3(0,0,1) tp = TangentPlane2(param,par1,par2,(0,0),_1(252,250,225)) tp.localOriginSphere.hide() tp.localYAxis.setColor(col).setWidth(2).show() Slider(rangep=('u', 0,2*pi,0,20),func=tp.setU, parent=self) Slider(rangep=('t', -1,1,0,20),func=tp.setV,parent=self) self.addChild(cilindro) self.addChild(tp)
def creaLoxodroma(self): tmin = -75 tmax = 60 pmin = 0 pmax = 2 * pi r = 3 r2 = r - 0.005 m = tan(pi / 60) t0 = pi / 2 def sigmoide(t): return abs(2.0/(1+exp(-(t/15.0)))-1) def func(t): t = t * sigmoide(t) return r * cos(-t) / cosh(m * (-t - t0)), r * sin(-t) / cosh(m * (-t - t0)), r * tanh(m * (-t - t0)) def cp(t): t = t * sigmoide(t) den1 = cosh(m * (-t - t0)) return Vec3(-r * sin(t) / den1 + r * cos(t) * sinh(m * (-t - t0)) * m / den1 ** 2, -r * cos(t) / den1 - r * sin(t) * sinh(m * (-t - t0)) * m / den1 ** 2, -r * (1 - tanh(m * (-t - t0)) ** 2) * m) curve = Curve3D(func, (tmin, tmax, 10), color=(1, 1, 0), width=3, nvertices=1, max_distance = .3, max_angle = .2) self.addChild(curve) tangent = curve.attachField("tangente", cp).setLengthFactor(1).setWidthFactor(.2).show() tangent.setRadius(.04) tangent.animation.setDuration(30000) matHead = SoMaterial() matHead.ambientColor = (.33, .22, .27) matHead.diffuseColor = (1, 0, 0) matHead.specularColor = (.99, .94, .81) matHead.shininess = .28 self.setupAnimations([ AnimationGroup([curve, tangent], (20000,0,len(curve)-1)) ]) resf = 2.97 esf = ParametricPlot3D(lambda t, f: (resf * sin(t) * cos(f), resf * sin(t) * sin(f), resf * cos(t)) , (0, pi, 100), (0, 2 * pi, 120)) esf.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) esf.setTransparency(0.4) esf.setDiffuseColor(_1(28, 119, 68)) self.addChild(esf) VisibleCheckBox("esfera", esf, True, parent=self) ## los meridianos sep = SoSeparator() mer = Curve3D(lambda t: (0, r2 * cos(t), r2 * sin(t)), (pmin, pmax, 100), color=_1(72, 131, 14)) for i in range(24): sep.addChild(rot(2 * pi / 24)) sep.addChild(mer.root) # highlighted meridians r3 = r + 0.005 mer2 = Curve3D(lambda t: (0, r3 * cos(t), r3 * sin(t)), (pmin, pmax, 100), color=_1(255, 251,0), width=2) for i in [-4, -2]: sep.addChild(rot(i * 2 * pi / 24)) sep.addChild(mer2.root) self.addChild(sep)
def __init__(self): Page.__init__( self, u"Hélice circular, curvatura y torsión<br><br>(cos s/√2, sen s/√2, s/√2)" ) self.camera_position = (10, -10, 10) self.showAxis(False) tmin = -2 * pi tmax = 2 * pi npuntos = 300 self.addChild(Cylinder(_1(185, 46, 61), tmax - tmin, 2)) ## ============================================ # 1 implica primer derivada, 2 implica segunda derivada def param1hc(t): return 2 * Vec3(cos(t), sin(t), t / 3.0) def param2hc(t): return 2 * Vec3(-sin(t), cos(t), 1 / 3.0) def param3hc(t): return 2 * Vec3(-cos(t), -sin(t), 0) def param4hc(t): return 2 * Vec3(sin(t) / 3.0, -cos(t) / 3.0, 1.0) espiral = Curve3D(param1hc, (tmin * 1.5, tmax * 1.5, npuntos), color=_1(255, 255, 255)) tangente = espiral.attachField( "tangente", param2hc).setLengthFactor(1).setWidthFactor(.6) tangente.setRadius(0.06) tangente.setDiffuseColor(_1(20, 240, 20)) normal = espiral.attachField( "normal", param3hc).setLengthFactor(1).setWidthFactor(.6) normal.setRadius(0.06) normal.setDiffuseColor(_1(240, 120, 20)) binormal = espiral.attachField( "binormal", param4hc).setLengthFactor(1).setWidthFactor(.6) binormal.setRadius(0.06) binormal.setDiffuseColor(_1(20, 120, 240)) self.addChild(espiral) self.setupAnimations([ AnimationGroup([tangente, normal, binormal], (10000, 0, len(espiral) - 1)) ])
def createEllipsoid(a,b,c): par_e = lambda u, v: Vec3(a * sin(v) * cos(u), b * sin(u) * sin(v), c * cos(v)) e = ParametricPlot3D(par_e, (0, 2*pi, 100), (0, pi, 100)) e.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) e.setTransparency(0.5) e.setDiffuseColor(_1(40, 200, 120)) return e
def createTorus(r1,r2): par_t = lambda u, v: Vec3((r1 + r2 * cos(v)) * cos(u), (r1 + r2 * cos(v)) * sin(u), r2 * sin(v)) tor = ParametricPlot3D(par_t, (-pi, pi, 100), (-pi, pi, 100)) tor.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) tor.setTransparency(0.5) tor.setDiffuseColor(_1(180, 220, 200)) return tor
def createHyperboloid(a,b): par_h = lambda u, v: Vec3(u, v, u**2/(a**2)-v**2/(b**2)) h = ParametricPlot3D(par_h, (-4, 4, 100), (-4, 4, 100)) h.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) h.setTransparency(0.5) h.setDiffuseColor(_1(220, 200, 80)) return h
def __init__(self): "x^2 + y^2 = z^2" Page.__init__(self, u"Semicono de revolución<br><br>F(θ,ρ)=(θ,ρ,π/4)") cono = RevolutionPlot3D(lambda r, t: r + 1, (0, 1), (0, 2 * pi)) cono1 = RevolutionPlot3D(lambda r, t, h: h * (r + 1), (0.05, 1), (0, 2 * pi)) #@UndefinedVariable cono1.setLinesVisible(True) cono1.setMeshVisible(False) cono.setDiffuseColor(_1(149, 24, 82)) cono.setSpecularColor(_1(149, 24, 82)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(cono) self.addChild(cono1) self.addChild(baseplane)
def __init__(self): "x^3 - 3xy^2 - z = 0" Page.__init__( self, u"Silla del mono<br><br>F(x,y)=(x, y, x<sup>3</sup> - 3xy<sup>2</sup>)" ) silla = Plot3D(lambda x, y: x**3 - 3 * x * y**2 + 2.5, (-1, 1), (-1, 1)) silla.setAmbientColor(_1(151, 139, 125)) silla.setDiffuseColor(_1(151, 139, 125)) silla.setSpecularColor(_1(151, 139, 125)) # silla.setShininess(1) # plano.setScaleFactor((1,1,.6)) def cVec(pto): "pto: Vec3" return pto * 1.1 silla.addVectorField(cVec) # def setXscale(t): # scale.scaleFactor = (1,1,t) # Slider( # rangep=('z', .2, 1, 1, 20), # func=setXscale, # parent=self # ) # silla1 = Plot3D(lambda x, y, h: h * (x**3 - 3 * x * y**2 + 2.5), (-1, 1), (-1, 1)) #@UndefinedVariable # silla1.setScaleFactor((1,1,.6)) silla1.setLinesVisible(True) silla1.setMeshVisible(False) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(silla) self.addChild(silla1) self.addChild(baseplane)
def __init__(self): "x^2 - y^2 - z = 0" Page.__init__(self, u"Paraboloide Hiperbólico<br><br>F(x,y)=(x, y, x<sup>2</sup>-y<sup>2</sup>)") z = 1.5 parab = Plot3D(lambda x, y: x ** 2 - y ** 2 + z, (-1, 1), (-1, 1)) parab1 = Plot3D(lambda x, y, h: h * (x ** 2 - y ** 2 + z), (-1, 1), (-1, 1)) #@UndefinedVariable parab1.setLinesVisible(True) parab1.setMeshVisible(False) parab.setAmbientColor(_1(145, 61 , 74)) parab.setDiffuseColor(_1(127, 119, 20)) parab.setSpecularColor(_1(145, 61 , 74)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(parab) self.addChild(parab1) self.addChild(baseplane)
def __init__(self): "x^2 + y^2 = z^2" Page.__init__( self, u"Semicono de revolución<br><br>F(θ,ρ)=(θ,ρ,π/4)" ) cono = RevolutionPlot3D(lambda r, t: r + 1, (0, 1), (0, 2 * pi)) cono1 = RevolutionPlot3D(lambda r, t, h: h * (r + 1), (0.05, 1), (0, 2 * pi)) #@UndefinedVariable cono1.setLinesVisible(True) cono1.setMeshVisible(False) cono.setDiffuseColor(_1(149, 24, 82)) cono.setSpecularColor(_1(149, 24, 82)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(cono) self.addChild(cono1) self.addChild(baseplane)
def __init__(self): super(Toro, self).__init__(u"Curvas tóricas") tmin, tmax, npuntos = (0, 2 * pi, 3000) a = 1 b = 0.5 c = 0.505 def toroParam1(u, v): return ((a + b * cos(v)) * cos(u), (a + b * cos(v)) * sin(u), b * sin(v)) def toroParam2(u, v): return ((a + c * cos(v)) * cos(u), (a + c * cos(v)) * sin(u), c * sin(v)) def curvaPlana(t): return (t, t) def curvaToro(t): return toroParam2(*curvaPlana(t)) toro = ParametricPlot3D(toroParam1, (0, 2 * pi, 150), (0, 2 * pi, 100)) toro.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) toro.setTransparency(0.4) curva = Curve3D(curvaToro, (tmin, tmax, npuntos), color=_1(146, 33, 86), width=3, nvertices=1) def recalculaCurva(**kargs): """a: vueltas horizontales, b: vueltas verticales""" keys = kargs.keys() if "a" in keys: recalculaCurva.a = kargs["a"] if "b" in keys: recalculaCurva.b = kargs["b"] def curvaPlana(t): return (recalculaCurva.a * t, recalculaCurva.b * t) def curvaToro(t): return toroParam2(*curvaPlana(t)) curva.updatePoints(curvaToro) recalculaCurva.a = 1 recalculaCurva.b = 1 sp1 = SpinBox("a", (0, 20, 1), lambda x: recalculaCurva(a=x), parent=self) sp2 = SpinBox("b", (0, 20, 1), lambda x: recalculaCurva(b=x), parent=self) self.addChild(curva) self.addChild(toro) curva.animation.setDuration(5000) self.setupAnimations([curva])
def __init__(self): Page.__init__(self, u"Campo en la esfera con sólo una singularidad") def make_circulo(t): return partial(par_esfera, t) par_esfera = lambda t, f: 0.99 * Vec3( sin(t) * cos(f), sin(t) * sin(f), cos(t)) esf = ParametricPlot3D(par_esfera, (0, pi, 100), (0, 2 * pi, 120)) esf.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) esf.setTransparency(0.4) esf.setDiffuseColor(_1(68, 28, 119)) VisibleCheckBox("esfera", esf, True, parent=self) self.addChild(esf) def par_curva(c, t): t = tan(t / (4 * pi)) den = c**2 + t**2 + 1 return Vec3(2 * c / den, 2 * t / den, (c**2 + t**2 - 1) / den) def par_tang(c, t): t = tan(t / (4 * pi)) den = (c**2 + t**2 + 1)**2 return Vec3(-2 * c * (2 * t) / den, (2 * (c**2 + t**2 + 1) - 4 * t**2) / den, 4 * t / den) def make_curva(c): return partial(par_curva, c) def make_tang(c): return partial(par_tang, c) tangentes = [] for c in range(-10, 11): ct = tan(c / (2 * pi)) curva = Curve3D(make_curva(ct), (-20, 20, 80), width=1) curva.attachField( "tangente", make_tang(ct)).setLengthFactor(1).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (10000, 0, 79)) self.setupAnimations([a1])
def __init__(self): "F(x,y) = (x, y, x + y - 6)" #u"""l plano x + y + z - 2.5 = 0""" Page.__init__(self, u"Plano<br><br>F(x,y) = (x, y, x + y - 6)") plane = lambda x, y: -x - y p1 = lambda x, y, t1: (x, y, (1 - t1) * (-x - y) - 2 * t1) p2 = lambda x, y, t2: (x, (1 - t2) * y - 2 * t2, -x - y) p3 = lambda x, y, t3: ((1 - t3) * x - 2 * t3, y, -x - y) r = (-1, 1, 15) plano = Plot3D(plane, (-1, 1), (-1, 1)) plano.setTransparencyType(8) plano1 = ParametricPlot3D(p1, r, r) plano2 = ParametricPlot3D(p2, r, r) plano3 = ParametricPlot3D(p3, r, r) planos = [plano1, plano2, plano3] for p in planos: p.linesVisible = True p.meshVisible = False plano1.setMeshDiffuseColor((1, 0, 0)) plano2.setMeshDiffuseColor((0, 1, 0)) plano3.setMeshDiffuseColor((0, 1, 1)) plano.diffuseColor = _1(29, 214, 216) plano.transparency = 0.5 plano.setAmbientColor(_1(29, 214, 216)) self.setupPlanes((-2, 2, 7)) self.addChildren([plano, plano1, plano2, plano3]) ## no controls for i, plano in enumerate(planos): plano.parameters['t%d' % (i + 1)].hide() self.setupAnimations([ plano.parameters['t%d' % (i + 1)].asAnimation() for i, plano in enumerate(planos) ])
def __init__(self): "x^3 - 3xy^2 - z = 0" Page.__init__(self, u"Silla del mono<br><br>F(x,y)=(x, y, x<sup>3</sup> - 3xy<sup>2</sup>)") silla = Plot3D(lambda x, y: x ** 3 - 3 * x * y ** 2 + 2.5, (-1, 1), (-1, 1)) silla.setAmbientColor(_1(151, 139, 125)) silla.setDiffuseColor(_1(151, 139, 125)) silla.setSpecularColor(_1(151, 139, 125)) # silla.setShininess(1) # plano.setScaleFactor((1,1,.6)) def cVec(pto): "pto: Vec3" return pto * 1.1 silla.addVectorField(cVec) # def setXscale(t): # scale.scaleFactor = (1,1,t) # Slider( # rangep=('z', .2, 1, 1, 20), # func=setXscale, # parent=self # ) # silla1 = Plot3D(lambda x, y, h: h * (x ** 3 - 3 * x * y ** 2 + 2.5), (-1, 1), (-1, 1)) #@UndefinedVariable # silla1.setScaleFactor((1,1,.6)) silla1.setLinesVisible(True) silla1.setMeshVisible(False) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(silla) self.addChild(silla1) self.addChild(baseplane)
def __init__(self): #u"""x^2 + y^2 + z^2 = 1""" super(EsferaCasquetes,self).__init__(u"Otro atlas de la esfera") r = .98 esf = ParametricPlot3D(lambda t, f: (r * sin(t) * cos(f), r * sin(t) * sin(f), r * cos(t)), (0, pi, 70), (0, 2 * pi, 70)) esf.setDiffuseColor(_1(99, 136, 63)) esf.setSpecularColor(_1(99, 136, 63)) pars = [ lambda u,v, t1: (u, v, 1.5-t1*(1.5-sqrt(1 - u**2 - v**2))), lambda u,v, t2: (u, v, -1.5-t2*(-1.5+sqrt(1 - u**2 - v**2))), lambda u,v, t3: (u, 1.5-t3*(1.5-sqrt(1 - u**2 - v**2)),v), lambda u,v, t4: (u, -1.5-t4*(-1.5+sqrt(1 - u**2 - v**2)),v), lambda u,v, t5: (1.5-t5*(1.5-sqrt(1 - u**2 - v**2)),u,v), lambda u,v, t6, : (-1.5-t6*(-1.5+sqrt(1 - u**2 - v**2)),u,v) ] d = 0.707106 colores = [(0,0,1),(0,0,1),(0,1,0),(0,1,0),(1,0,0),(1,0,0)] planos = [ParametricPlot3D(par, (-d, d, 40), (-d, d, 40)).setLinesVisible(True).setMeshVisible(False).setMeshDiffuseColor(colores[i]) for i,par in enumerate(pars)] baseplane = BasePlane() baseplane.setHeight(-1.005) baseplane.setRange((-2,2, 7)) self.addChild(esf) for p in planos: self.addChild(p) self.addChild(baseplane) ## no queremos los controles for i,plano in enumerate(planos): plano.parameters['t%d' % (i+1)].hide() anims = [plano.parameters['t%d' % (i+1)].asAnimation() for i,plano in enumerate(planos)] self.setupAnimations(anims)
def __init__(self): Page.__init__(self, u"Otro campo en el toro sin singularidades") a = 1 b = 0.5 def toroParam1(u, v): return ((a + b * cos(v)) * cos(u), (a + b * cos(v)) * sin(u), b * sin(v)) def toro_u(u, v): return Vec3(-(a + b * cos(v)) * sin(u), (a + b * cos(v)) * cos(u), 0) def toro_v(u, v): return Vec3(-b * sin(v) * cos(u), -b * sin(v) * sin(u), b * cos(v)) parab = ParametricPlot3D(toroParam1, (0, 2 * pi, 150), (0, 2 * pi, 100)) parab.setTransparency(0.4) parab.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): return lambda t: toroParam1(t, c) def make_tang(c): return lambda t: toro_u(t, c) tangentes = [] ncurves = 50 for c in range(0, ncurves + 1): ## -1 < ct < 1 ct = c / float(ncurves) * 2 * pi curva = Curve3D(make_curva(ct), (0, 2 * pi, 100), width=1) curva.attachField( "tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (6000, 0, 99)) self.setupAnimations([a1])
def __init__(self): "x^2 - y^2 - z = 0" Page.__init__( self, u"Paraboloide Hiperbólico<br><br>F(x,y)=(x, y, x<sup>2</sup>-y<sup>2</sup>)" ) z = 1.5 parab = Plot3D(lambda x, y: x**2 - y**2 + z, (-1, 1), (-1, 1)) parab1 = Plot3D(lambda x, y, h: h * (x**2 - y**2 + z), (-1, 1), (-1, 1)) #@UndefinedVariable parab1.setLinesVisible(True) parab1.setMeshVisible(False) parab.setAmbientColor(_1(145, 61, 74)) parab.setDiffuseColor(_1(127, 119, 20)) parab.setSpecularColor(_1(145, 61, 74)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(parab) self.addChild(parab1) self.addChild(baseplane)
def __init__(self): "x^4 + 2x^2y^2 + y^4 -z = 0" Page.__init__(self, u"Superficie cuártica<br><br>F(x,y)=(x,y,x<sup>4</sup>+2x<sup>2</sup>y<sup>2</sup>+y<sup>4</sup>)") # cuart = Plot3D(lambda x,y: x**4 + 2*x**2*y**2 + y**4 + 1, (-1,1),(-1,1)) cuart = RevolutionPlot3D(lambda r, t: r ** 4 + 1, (0, 1.4), (0, 2 * pi)) # cuart.setScaleFactor((1,1,.6)) mesh1 = Plot3D(lambda x, y, h: h * (x ** 4 + 2 * x ** 2 * y ** 2 + y ** 4 + 0.9), (-1, 1), (-1, 1)) mesh1.setLinesVisible(True) mesh1.setMeshVisible(False) mesh1.setBoundingBox(zrange=(-1, 6)) # cuart.setAmbientColor(_1(168,211,8)) cuart.setDiffuseColor(_1(168, 211, 8)) cuart.setSpecularColor(_1(168, 211, 8)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(cuart) self.addChild(mesh1) self.addChild(baseplane)
def __init__(self): Page.__init__(self, u"Campo en la esfera con sólo una singularidad") def make_circulo(t): return partial(par_esfera, t) par_esfera = lambda t, f: 0.99*Vec3(sin(t) * cos(f), sin(t) * sin(f), cos(t)) esf = ParametricPlot3D(par_esfera, (0, pi, 100), (0, 2 * pi, 120)) esf.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) esf.setTransparency(0.4) esf.setDiffuseColor(_1(68, 28, 119)) VisibleCheckBox("esfera", esf, True, parent=self) self.addChild(esf) def par_curva(c,t): t = tan(t/(4*pi)) den = c**2+t**2+1 return Vec3(2*c / den, 2*t / den, (c**2+t**2-1) / den) def par_tang(c,t): t = tan(t/(4*pi)) den = (c**2+t**2+1)**2 return Vec3(-2*c*(2*t) / den, (2*(c**2+t**2+1)-4*t**2) / den, 4*t / den) def make_curva(c): return partial(par_curva,c) def make_tang(c): return partial(par_tang,c) tangentes = [] for c in range(-10,11): ct = tan(c/(2*pi)) curva = Curve3D(make_curva(ct),(-20,20,80), width=1) curva.attachField("tangente", make_tang(ct)).setLengthFactor(1).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (10000, 0, 79)) self.setupAnimations([a1])
def __init__(self): Page.__init__( self, u"Campo sin singularidades en el plano<br><br>(x,y) → (1,0)") par_plano = lambda u, v: Vec3(u, v, 0) def plano_u(u, v): return Vec3(1, 0, 0) def plano_v(u, v): return Vec3(0, 1, 0) parab = ParametricPlot3D(par_plano, (-1, 1, 20), (-1, 1, 20)) parab.setTransparency(0.4) parab.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): return lambda t: par_plano(t, c) def make_tang(c): return lambda t: plano_u(t, c) tangentes = [] ncurves = 30 steps = 70 for c in range(0, ncurves + 1): ## -1 < ct < 1 ct = c / float(ncurves) * 2 - 1 curva = Curve3D(make_curva(ct), (-1, 1, steps), width=1) curva.attachField( "tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (6000, 0, steps - 1)) self.setupAnimations([a1])
def __init__(self): Page.__init__(self, u"Otro campo en el toro sin singularidades") a = 1 b = 0.5 def toroParam1(u,v): return ((a+b*cos(v))*cos(u),(a+b*cos(v))*sin(u),b*sin(v)) def toro_u(u,v): return Vec3(-(a+b*cos(v))*sin(u), (a+b*cos(v))*cos(u), 0) def toro_v(u,v): return Vec3(-b*sin(v)*cos(u), -b*sin(v)*sin(u), b*cos(v)) parab = ParametricPlot3D(toroParam1, (0,2*pi,150),(0,2*pi,100)) parab.setTransparency(0.4) parab.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): return lambda t: toroParam1(t,c) def make_tang(c): return lambda t: toro_u(t,c) tangentes = [] ncurves = 50 for c in range(0,ncurves+1): ## -1 < ct < 1 ct = c/float(ncurves) * 2*pi curva = Curve3D(make_curva(ct),(0,2*pi,100), width=1) curva.attachField("tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (6000, 0, 99)) self.setupAnimations([a1])
def __init__(self): Page.__init__(self, u"Campo sin singularidades en el plano<br><br>(x,y) → (1,0)") par_plano = lambda u, v: Vec3(u,v,0) def plano_u(u,v): return Vec3(1,0,0) def plano_v(u,v): return Vec3(0,1,0) parab = ParametricPlot3D(par_plano, (-1,1,20),(-1,1,20)) parab.setTransparency(0.4) parab.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): return lambda t: par_plano(t,c) def make_tang(c): return lambda t: plano_u(t,c) tangentes = [] ncurves = 30 steps = 70 for c in range(0,ncurves+1): ## -1 < ct < 1 ct = c/float(ncurves) * 2 - 1 curva = Curve3D(make_curva(ct),(-1,1,steps), width=1) curva.attachField("tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (6000, 0, steps-1)) self.setupAnimations([a1])
def __init__(self): Page.__init__( self, u"Hélice circular reflejada<br><br>(cos s/√2, sen s/√2, -s/√2)" ) self.camera_position = (10, -10, 10) self.showAxis(False) tmin, tmax, npuntos = (-2 * pi, 2 * pi, 200) self.addChild(Cylinder(_1(7, 83, 150), tmax - tmin, 2)) def param1hr(t): return 2 * Vec3(cos(t), sin(t), -t / 3.0) def param2hr(t): return 2 * Vec3(-sin(t), cos(t), -1 / 3.0) def param3hr(t): return 2 * Vec3(-cos(t), -sin(t), 0) espiral = Curve3D(param1hr, (tmin * 1.5, tmax * 1.5, npuntos), color=_1(240, 10, 120)) def param1hc_der(t): return 2 * Vec3(cos(t), sin(t), t / 3.0) espiral_der = Curve3D(param1hc_der, (tmin * 1.5, tmax * 1.5, npuntos), color=_1(20, 240, 240)) tangente = espiral.attachField( "tangente", param2hr).setLengthFactor(1).setWidthFactor(.6) tangente.setRadius(0.06) tangente.setDiffuseColor(_1(20, 240, 20)) normal = espiral.attachField( "normal", param3hr).setLengthFactor(1).setWidthFactor(.6) normal.setRadius(0.06) normal.setDiffuseColor(_1(240, 120, 20)) self.addChild(espiral) self.addChild(espiral_der) plano_xy_par = lambda u, v: Vec3(u, v, 0) plano_xy = ParametricPlot3D(plano_xy_par, (-4, 4, 20), (-4, 4, 20)) plano_xy.setDiffuseColor(_1(200, 200, 200)) plano_xy.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) plano_xy.setTransparency(0.85) self.addChild(plano_xy) self.addChild(Line([(-4, 0, 0), (4, 0, 0)], color=(0.8, 0.8, 0.5))) self.addChild(Line([(0, -4, 0), (0, 4, 0)], color=(0.8, 0.8, 0.5))) self.setupAnimations( [AnimationGroup([tangente, normal], (10000, 0, len(espiral) - 1))])
def __init__(self): Page.__init__( self, u"Otro campo en el paraboloide hiperbólico sin singularidades<br><br>(x,y) → (0, 1, x)" ) par_parab = lambda x, y: Vec3(x, y, x * y) par_tang = lambda x, y: Vec3(0, 1, x) parab = ParametricPlot3D(par_parab, (-1, 1), (-1, 1)) parab.setTransparency(0.4) parab.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): return partial(par_parab, c) def make_tang(c): return partial(par_tang, c) tangentes = [] for c in range(0, 21): ## -1 < ct < 1 ct = 2 * c / 20.0 - 1 curva = Curve3D(make_curva(ct), (-1, 1, 50), width=1) curva.attachField( "tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (6000, 0, 49)) self.setupAnimations([a1])
def __init__(self): Page.__init__(self, u"Campo en la esfera con dos singularidades") par_esfera = lambda u, v: Vec3( sin(u) * cos(v), sin(u) * sin(v), cos(u)) def esfera_u(u, v): return Vec3(cos(u) * cos(v), cos(u) * sin(v), -sin(u)) def esfera_v(u, v): return Vec3(-sin(u) * sin(v), cos(v) * sin(u), 0) parab = ParametricPlot3D(par_esfera, (0, 2, 150), (0, 2 * pi, 100)) parab.setTransparency(0.4) parab.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): return partial(par_esfera, c) def make_tang(c): return partial(esfera_v, c) tangentes = [] curves = [] ncurves = 70 for c in range(0, ncurves + 1): ## -1 < ct < 1 ct = c / float(ncurves) * pi curve = Curve3D(make_curva(ct), (0, 2 * pi, 100), width=1) tangent = curve.attachField( "tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1).show() tangentes.append(tangent) curves.append(curve) self.addChildren(curves) self.setupAnimations([AnimationGroup(tangentes, (6000, 0, 99))])
def __init__(self): Page.__init__(self, u"Otro campo en el paraboloide hiperbólico sin singularidades<br><br>(x,y) → (0, 1, x)") par_parab = lambda x, y: Vec3(x,y,x*y) par_tang = lambda x,y: Vec3(0,1,x) parab = ParametricPlot3D(par_parab, (-1, 1), (-1, 1)) parab.setTransparency(0.4) parab.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): return partial(par_parab,c) def make_tang(c): return partial(par_tang,c) tangentes = [] for c in range(0,21): ## -1 < ct < 1 ct = 2*c/20.0-1 curva = Curve3D(make_curva(ct),(-1,1,50), width=1) curva.attachField("tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (6000, 0, 49)) self.setupAnimations([a1])
def __init__(self): Page.__init__(self, u"Hélice circular reflejada<br><br>(cos s/√2, sen s/√2, -s/√2)") self.camera_position = (10, -10, 10) self.showAxis(False) tmin, tmax, npuntos = (-2 * pi, 2 * pi, 200) self.addChild(Cylinder(_1(7, 83, 150), tmax - tmin, 2)) def param1hr(t): return 2*Vec3(cos(t), sin(t), -t/3.0) def param2hr(t): return 2*Vec3(-sin(t), cos(t), -1/3.0) def param3hr(t): return 2*Vec3(-cos(t), -sin(t), 0) espiral = Curve3D(param1hr, (tmin*1.5, tmax*1.5, npuntos), color=_1(240, 10, 120)) def param1hc_der(t): return 2*Vec3(cos(t), sin(t), t/3.0) espiral_der = Curve3D(param1hc_der, (tmin*1.5, tmax*1.5, npuntos), color=_1(20, 240, 240)) tangente = espiral.attachField("tangente", param2hr).setLengthFactor(1).setWidthFactor(.6) tangente.setRadius( 0.06 ) tangente.setDiffuseColor( _1(20,240,20) ) normal = espiral.attachField("normal", param3hr).setLengthFactor(1).setWidthFactor(.6) normal.setRadius( 0.06 ) normal.setDiffuseColor( _1(240,120,20) ) self.addChild(espiral) self.addChild(espiral_der) plano_xy_par = lambda u, v: Vec3(u,v,0) plano_xy = ParametricPlot3D(plano_xy_par, (-4,4,20),(-4,4,20)) plano_xy.setDiffuseColor( _1(200,200,200) ) plano_xy.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) plano_xy.setTransparency( 0.85 ) self.addChild( plano_xy ) self.addChild(Line([(-4, 0, 0), (4, 0, 0)], color=(0.8, 0.8, 0.5))) self.addChild(Line([(0, -4, 0), (0, 4, 0)], color=(0.8, 0.8, 0.5))) self.setupAnimations([ AnimationGroup([tangente, normal], (10000,0,len(espiral)-1)) ])
def __init__(self): Page.__init__( self, u"Campo en el paraboloide hiperbólico con una singularidad<br><br>(x,y) → (0, 1, -k/x<sup>2</sup>)" ) par_parab = lambda x, y: Vec3(x, y, x * y) par_tang = lambda x, y: Vec3(0, 1, x) parab = ParametricPlot3D(par_parab, (-1, 1), (-1, 1)) parab.setTransparency(0.4) parab.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): #return partial(par_parab,c) return lambda x: Vec3(x, c / x, c * 1.01) def make_curva_negy(c): #return partial(par_parab,c) return lambda x: Vec3(x, -c / x, -c * 0.99) def make_tang(c): #return partial(par_tang,c) return lambda x: Vec3(x, -c / (x**2), 0.0) / (sqrt(x**2 + c**2 / (x**4))) def make_tang_negy(c): #return partial(par_tang,c) return lambda x: Vec3(x, c / (x**2), 0.0) / (sqrt(x**2 + c**2 / (x**4))) tangentes = [] for c in range(1, 10): ## 0 < ct < 1 ct = c / 10.0 curva = Curve3D(make_curva(ct), (ct, 1.0, 50), width=1.5) curva.attachField( "tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) curva = Curve3D(make_curva_negy(ct), (ct, 1.0, 50), width=1.5) curva.attachField( "tangente_negy", make_tang_negy(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente_negy'].show() tangentes.append(curva.fields['tangente_negy']) self.addChild(curva) #ct = -1.0 + c/10.0 curva = Curve3D(make_curva(ct), (-ct, -1.0, 50), width=1.5) curva.attachField( "tangente2", make_tang(-ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente2'].show() tangentes.append(curva.fields['tangente2']) self.addChild(curva) curva = Curve3D(make_curva_negy(ct), (-ct, -1.0, 50), width=1.5) curva.attachField( "tangente_negy2", make_tang_negy(-ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente_negy2'].show() tangentes.append(curva.fields['tangente_negy2']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (5000, 0, 49)) self.setupAnimations([a1]) self.addChild( Line([(-1, 0, 0.01), (1, 0, 0.01)], color=(1, 1, 1)).setWidth(1.5)) self.addChild( Line([(0, -1, 0.01), (0, 1, 0.01)], color=(1, 1, 1)).setWidth(1.5))
def __init__(self): super(Toro1,self).__init__(u'Secciones normales de un toro en un punto elíptico') self.showAxis(False) torus = createTorus(r1, r2) self.addChild(torus) normal = Arrow((r1+r2,0,0), (r1+r2+1,0,0), 0.03) self.addChild(normal) class TorusCurve(object): def __init__(self, t=0.0): self.param = t def __call__(self, s): param1 = pi_2*self.param #/1000.0 cosp = cos(param1) sinp = sin(param1) u = s #*rot btor = 2.0*u**2 + 16.0 - 36.0*sinp**2 v = sqrt( (-btor+sqrt(btor**2 - 4.0*(u**4-20.0*u**2+64.0)) )/2.0 ) return Vec3(u, sinp*v, cosp*v) def setParam(self, t): self.param = t torusc_obj = TorusCurve() curve = Curve3DParam(torusc_obj, (2.0, 4.0, 200), color=(0.9, 0.2, 0.1), width=6) class TorusCurve2(object): def __init__(self, t=0.0): self.param = t def __call__(self, s): param1 = pi_2*self.param #/1000.0 cosp = cos(param1) sinp = sin(param1) u = s #*rot btor = 2.0*u**2 + 16.0 - 36.0*sinp**2 v = -sqrt( (-btor+sqrt(btor**2 - 4.0*(u**4-20.0*u**2+64.0)) )/2.0 ) return Vec3(u, sinp*v, cosp*v) def setParam(self, t): self.param = t torusc2_obj = TorusCurve2() curve2 = Curve3DParam(torusc2_obj, (2.0, 4.0, 200), color=(0.9, 0.2, 0.1), width=6) normal_plane_function = lambda u, v: (u, sin(pi_2*tt1)*v, cos(pi_2*tt1)*v) normal_plane_function.func_globals['tt1']=0.0 normal_plane = ParametricPlot3D(normal_plane_function, (-4.1, 4.1), (-4.1, 4.1)) normal_plane.setTransparency(0.75) normal_plane.setTransparencyType(SoTransparencyType.SCREEN_DOOR) #normal_plane.animation = normal_plane.parameters['tt1'].asAnimation() VisibleCheckBox("Plano Normal", normal_plane, True, parent=self) def basePoint(t): return Vec3(r1+r2,0,0) def endTangentPoint(t): # ||curve'(0)|| s = pi_2*t #/1000.0 return Vec3(r1+r2, sin(s), cos(s)) def endCurvaturePoint(t): # ||curve'(0)||**2 s = t #/1000.0 #vn = (b*sin(s))**2 + (c*cos(s))**2 # ||curve''(0)|| return Vec3(r1+s*(r2-1/r1), 0, 0) tangent_arrow = AnimatedArrow(basePoint, endTangentPoint) tangent_arrow.setDiffuseColor(_1(20,10,220)) curvature_arrow = AnimatedArrow(basePoint, endCurvaturePoint) curvature_arrow.setDiffuseColor(_1(220,200,20)) objects = [curve, curve2, normal_plane, tangent_arrow, curvature_arrow] self.addChildren( objects ) def setSyncParam(t): normal_plane_function.func_globals['tt1']=t normal_plane.updateAll() curve.setParam(t) curve2.setParam(t) tangent_arrow.animateArrow(t) curvature_arrow.animateArrow(t) Slider(rangep=('t', 0,1.0,0,40),func=setSyncParam, duration=4000, parent=self)
def __init__(self): Page.__init__(self, u"Campo de Morse sobre el toro") def coreTorusAt(p): dyz = sqrt( p[1]**2 + p[2]**2 ) return Vec3( 0.0, a*p[1]/dyz, a*p[2]/dyz ) def unitNormalToTorusAt(p): core = coreTorusAt(p) p_core = p - core dp_core = p_core.length() return p_core / dp_core def projAtTorus(p): core = coreTorusAt(p) p_core = p - core factor = 1.01*b / p_core.length() #un poco más de 1 para que se vea mejor... return core + factor * p_core def valMorseFieldAt(p): n = unitNormalToTorusAt(p) gdotn = -g*n[2] return Vec3( gdotn*n[0], gdotn*n[1], g + gdotn*n[2] ) def nextPoint(p,dt): return projAtTorus( p + dt*valMorseFieldAt(p) ) class CurveVectorField: def __init__(self, c): self.curve = c def basePoint(self, t): return self.curve[int(t)] def endPoint(self, t): return self.curve[int(t)] + valMorseFieldAt( self.curve[int(t)] ) curves = [] vectorial_fields_curves = [] vectorial_fields_curves_bk = [] dtheta = 2.0*pi/20.0 for nrot in range(0,20): points_down_curve = [] points_up_curve = [] q = Vec3( b*cos(nrot*dtheta), a+b*sin(nrot*dtheta), 0.0 ) # calculo empezando enmedio del toro for n in range(0,100): p = projAtTorus(q) v = valMorseFieldAt(p) if v.length() < 0.01: break points_down_curve.append(p) points_up_curve.append( Vec3( p[0], p[1], -p[2] ) ) q = nextPoint(p, 0.05) points_down_curve.reverse() # recorrer de arriba a enmedio points_down_curve.pop() # quitar los puntos de enmedio, repetidos en las listas points_down_curve.extend( points_up_curve ) # unir listas points_down_curve.reverse() curve = Line(points_down_curve, width=2.5) curves.append( curve ) cvf = CurveVectorField(curve) vectorial_fields_curves_bk.append(cvf) arrow = AnimatedArrow( cvf.basePoint, cvf.endPoint ) arrow.setDiffuseColor(_1(220,40,20)) arrow.setWidthFactor( 0.25 ) arrow.add_tail( 0.025 ) vectorial_fields_curves.append( arrow ) # la otra mitad del toro... reflejando por el eje Z points_reflected_curve = [] for p in points_down_curve: points_reflected_curve.append( Vec3( -p[0], -p[1], p[2] ) ) curveR = Line(points_reflected_curve, width=2.5) curves.append( curveR ) cvf = CurveVectorField(curveR) vectorial_fields_curves_bk.append(cvf) arrow = AnimatedArrow( cvf.basePoint, cvf.endPoint ) arrow.setDiffuseColor(_1(220,40,20)) arrow.setWidthFactor( 0.25 ) arrow.add_tail( 0.025 ) vectorial_fields_curves.append( arrow ) # paralelos hasta arriba points_curve1 = [] q = Vec3( 0.25, 0.0, a+b ) for n in range(0,100): p = projAtTorus(q) v = valMorseFieldAt(p) if v.length() < 0.01: break points_curve1.append(p) q = nextPoint(p, 0.05) curve1 = Line(points_curve1, width=2.5) curves.append( curve1 ) cvf = CurveVectorField(curve1) vectorial_fields_curves_bk.append(cvf) arrow = AnimatedArrow( cvf.basePoint, cvf.endPoint ) arrow.setDiffuseColor(_1(220,40,20)) arrow.setWidthFactor( 0.25 ) arrow.add_tail( 0.025 ) vectorial_fields_curves.append( arrow ) points_curve2 = [] q = Vec3( -0.25, 0.0, a+b ) for n in range(0,100): p = projAtTorus(q) v = valMorseFieldAt(p) if v.length() < 0.01: break points_curve2.append(p) q = nextPoint(p, 0.05) curve2 = Line(points_curve2, width=2.5) curves.append( curve2 ) cvf = CurveVectorField(curve2) vectorial_fields_curves_bk.append(cvf) arrow = AnimatedArrow( cvf.basePoint, cvf.endPoint ) arrow.setDiffuseColor(_1(220,40,20)) arrow.setWidthFactor( 0.25 ) arrow.add_tail( 0.025 ) vectorial_fields_curves.append( arrow ) self.addChildren( curves ) self.addChildren( vectorial_fields_curves ) def setSyncParam(t): for i in range(0, len(vectorial_fields_curves)): curve = curves[i] if t < len( curve.getPoints() ): vec_field = vectorial_fields_curves[i] #vec_field.animateArrow(int(t)) vec_field.animateArrow(t) Slider(rangep=('t', 0,198,1,199), func=setSyncParam, duration=16000, parent=self) # T(u,v) def toroParam1(u,v): return (b*sin(u),(a+b*cos(u))*cos(v),(a+b*cos(u))*sin(v)) def toroParam(u,v): return Vec3(b*sin(u),(a+b*cos(u))*cos(v),(a+b*cos(u))*sin(v)) paratoro = ParametricPlot3D(toroParam1, (0,2*pi,150),(0,2*pi,100)) paratoro.setTransparency(0.25) paratoro.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) paratoro.setDiffuseColor(_1(68, 28, 119)) self.addChild(paratoro) critic1 = Sphere( center=Vec3(0,0,a+b), radius=0.075, color=_1(240,10,20) ) critic2 = Sphere( center=Vec3(0,0,a-b), radius=0.075, color=_1(240,10,20) ) critic3 = Sphere( center=Vec3(0,0,-a+b), radius=0.075, color=_1(240,10,20) ) critic4 = Sphere( center=Vec3(0,0,-a-b), radius=0.075, color=_1(240,10,20) ) self.addChild(critic1) self.addChild(critic2) self.addChild(critic3) self.addChild(critic4)
def __init__(self): Page.__init__(self, u"Construcción de un vector del campo de Morse sobre el toro") def coreTorusAt(p): dyz = sqrt( p[1]**2 + p[2]**2 ) return Vec3( 0.0, a*p[1]/dyz, a*p[2]/dyz ) def unitNormalToTorusAt(p): core = coreTorusAt(p) p_core = p - core dp_core = p_core.length() return p_core / dp_core def projAtTorus(p): core = coreTorusAt(p) p_core = p - core factor = 1.005*b / p_core.length() #un poco más de 1 para que se vea mejor... return core + factor * p_core def valMorseFieldAt(p): n = unitNormalToTorusAt(p) gdotn = -g*n[2] return Vec3( gdotn*n[0], gdotn*n[1], g + gdotn*n[2] ) def nextPoint(p,dt): return projAtTorus( p + dt*valMorseFieldAt(p) ) class CurveVectorField: def __init__(self, c): self.curve = c def basePoint(self, t): return self.curve[int(t)] def endPoint(self, t): return self.curve[int(t)] + valMorseFieldAt( self.curve[int(t)] ) class CurveNormalField: def __init__(self, c): self.curve = c def basePoint(self, t): return self.curve[int(t)] def endPoint(self, t): return self.curve[int(t)] + unitNormalToTorusAt( self.curve[int(t)] ) class CurveGravityField: def __init__(self, c): self.curve = c def basePoint(self, t): return self.curve[int(t)] def endPoint(self, t): return self.curve[int(t)] + Vec3( 0, 0, g ) curves = [] vectorial_fields_curves = [] vectorial_fields_curves_bk = [] dtheta = pi/10.0 nrot = -4 points_down_curve = [] points_up_curve = [] q = Vec3( b*cos(nrot*dtheta), a+b*sin(nrot*dtheta), 0.0 ) # calculo empezando enmedio del toro for n in range(0,100): p = projAtTorus(q) v = valMorseFieldAt(p) if v.length() < 0.01: break points_down_curve.append(p) points_up_curve.append( Vec3( p[0], p[1], -p[2] ) ) q = nextPoint(p, 0.05) #Tangent Plane p = projAtTorus(q) p[2] = -p[2] v = valMorseFieldAt(p) u = v.cross( unitNormalToTorusAt(p) ) tangent_plane = Plane( _1(200,200,200), p, v+p, u+p ) points_down_curve.reverse() # recorrer de arriba a enmedio points_down_curve.pop() # quitar los puntos de enmedio, repetidos en las listas points_down_curve.extend( points_up_curve ) # unir listas points_down_curve.reverse() curve = Line(points_down_curve, width=2.5) curves.append( curve ) cvf = CurveVectorField(curve) vectorial_fields_curves_bk.append(cvf) arrow = AnimatedArrow( cvf.basePoint, cvf.endPoint ) arrow.setDiffuseColor(_1(220,40,200)) arrow.setWidthFactor( 0.48 ) arrow.add_tail( 0.025 ) vectorial_fields_curves.append( arrow ) cnf = CurveNormalField(curve) vectorial_fields_curves_bk.append(cnf) arrown = AnimatedArrow( cnf.basePoint, cnf.endPoint ) arrown.setDiffuseColor(_1(220,240,20)) arrown.setWidthFactor( 0.4 ) #arrown.add_tail( 0.025 ) vectorial_fields_curves.append( arrown ) cgf = CurveGravityField(curve) vectorial_fields_curves_bk.append(cgf) arrowg = AnimatedArrow( cgf.basePoint, cgf.endPoint ) arrowg.setDiffuseColor(_1(10,240,20)) arrowg.setWidthFactor( 0.4 ) #arrowg.add_tail( 0.025 ) vectorial_fields_curves.append( arrowg ) self.addChildren( curves ) self.addChildren( vectorial_fields_curves ) self.addChild( tangent_plane ) def setSyncParam(t): for i in range(0, len(vectorial_fields_curves)): #curve = curves[i] if t < len( curves[0].getPoints() ): vec_field = vectorial_fields_curves[i] vec_field.animateArrow(t) q = (curves[0])[int(t)] p = projAtTorus(q) v = valMorseFieldAt(p) u = v.cross( unitNormalToTorusAt(p) ) tangent_plane.setPoints( p, v+p, u+p ) Slider(rangep=('t', 0,198,1,199), func=setSyncParam, duration=8000, parent=self) # T(u,v) def toroParam1(u,v): return (b*sin(u),(a+b*cos(u))*cos(v),(a+b*cos(u))*sin(v)) def toroParam(u,v): return Vec3(b*sin(u),(a+b*cos(u))*cos(v),(a+b*cos(u))*sin(v)) paratoro = ParametricPlot3D(toroParam1, (0,2*pi,150),(0,2*pi,100)) paratoro.setTransparency(0.25) paratoro.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) paratoro.setTransparencyType(SoTransparencyType.SCREEN_DOOR) paratoro.setDiffuseColor(_1(68, 28, 119)) self.addChild(paratoro)
def __init__(self): super(Toro3,self).__init__(u'Secciones normales de un toro en un punto hiperbólico') self.showAxis(False) torus = createTorus(r1, r2) self.addChild(torus) normal = Arrow((r1-r2,0,0), (r1-r2-1,0,0), 0.03) self.addChild(normal) class TorusCurve(object): def __init__(self, t=0.0): self.param = t def __call__(self, s): param1 = pi_2*self.param #/1000.0 cosp = cos(param1) sinp = sin(param1) v = s btor = 2.0*v**2 - 20.0 ctor = v**4 + (16.0 - 36.0*sinp**2)*v**2 + 64.0 dis = btor**2 - 4.0*ctor if dis < 0.0: #v = 0.0 u = 4.0 else: inside = -btor-sqrt(dis) if inside < 0.0: #v = 0.0 u = 4.0 else: u = sqrt( inside/2.0 ) return Vec3(u, sinp*v, -cosp*v) def setParam(self, t): self.param = t torusc_obj = TorusCurve() curve = Curve3DParam(torusc_obj, (-2.0, 2.0, 200), color=(0.9, 0.2, 0.1), width=6) curve.setBoundingBox((-0.05,2.95),(-4.1,4.1),(-1.1,1.1)) normal_plane_function = lambda u, v: (u, sin(pi_2*tt3)*v, -cos(pi_2*tt3)*v) normal_plane_function.func_globals['tt3']=t normal_plane = ParametricPlot3D(normal_plane_function, (-4.1, 4.1), (-4.1, 4.1)) normal_plane.setTransparency(0.75) normal_plane.setTransparencyType(SoTransparencyType.SCREEN_DOOR) #normal_plane.animation = normal_plane.parameters['tt3'].asAnimation() VisibleCheckBox("Plano Normal", normal_plane, True, parent=self) def basePoint(t): return Vec3(r1-r2,0,0) def endTangentPoint(t): # ||curve'(0)|| s = pi_2*t #/1000.0 #vn = sqrt((b*sin(s))**2 + (c*cos(s))**2) return Vec3(r1-r2, -sin(s), cos(s)) def endCurvaturePoint(t): # ||curve'(0)||**2 #s = pi_2*t/1000.0 s = t #/1000.0 #vn = (b*sin(s))**2 + (c*cos(s))**2 # ||curve''(0)|| # nn = a return Vec3(r1-2*s*r2, 0, 0) tangent_arrow = AnimatedArrow(basePoint, endTangentPoint) tangent_arrow.setDiffuseColor(_1(20,10,220)) curvature_arrow = AnimatedArrow(basePoint, endCurvaturePoint) curvature_arrow.setDiffuseColor(_1(220,200,20)) objects = [curve, normal_plane, tangent_arrow, curvature_arrow] self.addChildren( objects ) def setSyncParam(t): normal_plane_function.func_globals['tt3']=t normal_plane.updateAll() curve.setParam(t) tangent_arrow.animateArrow(t) curvature_arrow.animateArrow(t) Slider(rangep=('t', 0,1.0,0,40),func=setSyncParam, duration=4000, parent=self)
def __init__(self): Page.__init__(self, u"Campo de Morse sobre el toro") def coreTorusAt(p): dyz = sqrt(p[1]**2 + p[2]**2) return Vec3(0.0, a * p[1] / dyz, a * p[2] / dyz) def unitNormalToTorusAt(p): core = coreTorusAt(p) p_core = p - core dp_core = p_core.length() return p_core / dp_core def projAtTorus(p): core = coreTorusAt(p) p_core = p - core factor = 1.01 * b / p_core.length( ) #un poco más de 1 para que se vea mejor... return core + factor * p_core def valMorseFieldAt(p): n = unitNormalToTorusAt(p) gdotn = -g * n[2] return Vec3(gdotn * n[0], gdotn * n[1], g + gdotn * n[2]) def nextPoint(p, dt): return projAtTorus(p + dt * valMorseFieldAt(p)) class CurveVectorField: def __init__(self, c): self.curve = c def basePoint(self, t): return self.curve[int(t)] def endPoint(self, t): return self.curve[int(t)] + valMorseFieldAt(self.curve[int(t)]) curves = [] vectorial_fields_curves = [] vectorial_fields_curves_bk = [] dtheta = 2.0 * pi / 20.0 for nrot in range(0, 20): points_down_curve = [] points_up_curve = [] q = Vec3(b * cos(nrot * dtheta), a + b * sin(nrot * dtheta), 0.0) # calculo empezando enmedio del toro for n in range(0, 100): p = projAtTorus(q) v = valMorseFieldAt(p) if v.length() < 0.01: break points_down_curve.append(p) points_up_curve.append(Vec3(p[0], p[1], -p[2])) q = nextPoint(p, 0.05) points_down_curve.reverse() # recorrer de arriba a enmedio points_down_curve.pop( ) # quitar los puntos de enmedio, repetidos en las listas points_down_curve.extend(points_up_curve) # unir listas points_down_curve.reverse() curve = Line(points_down_curve, width=2.5) curves.append(curve) cvf = CurveVectorField(curve) vectorial_fields_curves_bk.append(cvf) arrow = AnimatedArrow(cvf.basePoint, cvf.endPoint) arrow.setDiffuseColor(_1(220, 40, 20)) arrow.setWidthFactor(0.25) arrow.add_tail(0.025) vectorial_fields_curves.append(arrow) # la otra mitad del toro... reflejando por el eje Z points_reflected_curve = [] for p in points_down_curve: points_reflected_curve.append(Vec3(-p[0], -p[1], p[2])) curveR = Line(points_reflected_curve, width=2.5) curves.append(curveR) cvf = CurveVectorField(curveR) vectorial_fields_curves_bk.append(cvf) arrow = AnimatedArrow(cvf.basePoint, cvf.endPoint) arrow.setDiffuseColor(_1(220, 40, 20)) arrow.setWidthFactor(0.25) arrow.add_tail(0.025) vectorial_fields_curves.append(arrow) # paralelos hasta arriba points_curve1 = [] q = Vec3(0.25, 0.0, a + b) for n in range(0, 100): p = projAtTorus(q) v = valMorseFieldAt(p) if v.length() < 0.01: break points_curve1.append(p) q = nextPoint(p, 0.05) curve1 = Line(points_curve1, width=2.5) curves.append(curve1) cvf = CurveVectorField(curve1) vectorial_fields_curves_bk.append(cvf) arrow = AnimatedArrow(cvf.basePoint, cvf.endPoint) arrow.setDiffuseColor(_1(220, 40, 20)) arrow.setWidthFactor(0.25) arrow.add_tail(0.025) vectorial_fields_curves.append(arrow) points_curve2 = [] q = Vec3(-0.25, 0.0, a + b) for n in range(0, 100): p = projAtTorus(q) v = valMorseFieldAt(p) if v.length() < 0.01: break points_curve2.append(p) q = nextPoint(p, 0.05) curve2 = Line(points_curve2, width=2.5) curves.append(curve2) cvf = CurveVectorField(curve2) vectorial_fields_curves_bk.append(cvf) arrow = AnimatedArrow(cvf.basePoint, cvf.endPoint) arrow.setDiffuseColor(_1(220, 40, 20)) arrow.setWidthFactor(0.25) arrow.add_tail(0.025) vectorial_fields_curves.append(arrow) self.addChildren(curves) self.addChildren(vectorial_fields_curves) def setSyncParam(t): for i in range(0, len(vectorial_fields_curves)): curve = curves[i] if t < len(curve.getPoints()): vec_field = vectorial_fields_curves[i] #vec_field.animateArrow(int(t)) vec_field.animateArrow(t) Slider(rangep=('t', 0, 198, 1, 199), func=setSyncParam, duration=16000, parent=self) # T(u,v) def toroParam1(u, v): return (b * sin(u), (a + b * cos(u)) * cos(v), (a + b * cos(u)) * sin(v)) def toroParam(u, v): return Vec3(b * sin(u), (a + b * cos(u)) * cos(v), (a + b * cos(u)) * sin(v)) paratoro = ParametricPlot3D(toroParam1, (0, 2 * pi, 150), (0, 2 * pi, 100)) paratoro.setTransparency(0.25) paratoro.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) paratoro.setDiffuseColor(_1(68, 28, 119)) self.addChild(paratoro) critic1 = Sphere(center=Vec3(0, 0, a + b), radius=0.075, color=_1(240, 10, 20)) critic2 = Sphere(center=Vec3(0, 0, a - b), radius=0.075, color=_1(240, 10, 20)) critic3 = Sphere(center=Vec3(0, 0, -a + b), radius=0.075, color=_1(240, 10, 20)) critic4 = Sphere(center=Vec3(0, 0, -a - b), radius=0.075, color=_1(240, 10, 20)) self.addChild(critic1) self.addChild(critic2) self.addChild(critic3) self.addChild(critic4)
def __init__(self): Page.__init__(self, u"Campo de Morse sobre el toro") a = 2.0 b = 1.0 g = -1.25 # T(u,v) def toroParam1(u, v): return (b * sin(u), (a + b * cos(u)) * cos(v), (a + b * cos(u)) * sin(v)) def toroNormal(u, v): coef = b * (a + b * cos(u)) return Vec3(coef * sin(u), coef * cos(u) * cos(v), coef * cos(u) * sin(v)) def toroMorse(u, v): #coef = -b * ( a + b * cos(u) ) coef2 = -g * cos(u) * sin(v) return Vec3(coef2 * sin(u), coef2 * cos(u) * cos(v), g + coef2 * cos(u) * sin(v)) paratoro = ParametricPlot3D(toroParam1, (0, 2 * pi, 150), (0, 2 * pi, 100)) paratoro.setTransparency(0.25) paratoro.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) paratoro.setDiffuseColor(_1(68, 28, 119)) self.addChild(paratoro) def make_curva(c): return lambda t: toroParam1(c, t) def make_curva2(c): return lambda t: toroParam1(c, -t) def make_tang(c): return lambda t: toroMorse(c, t) def make_tang2(c): return lambda t: toroMorse(c, -t) tangentes = [] tangentes2 = [] ncurves = 12 for c in range(0, ncurves + 1): ## -1 < ct < 1 ct = c / float(ncurves) * 2 * pi #curva = Curve3D(make_curva(ct),(-pi/2,pi/2,100), width=0.5) curva = Curve3D(make_curva(ct), (pi / 2, 3 * pi / 2, 100), width=0.5) curva.attachField( "tangente", make_tang(ct)).setLengthFactor(1).setWidthFactor(.5) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) ### ct2 = c / float(ncurves) * 2 * pi #curva2 = Curve3D(make_curva2(ct2),(pi/2,3*pi/2,100), width=0.5) curva2 = Curve3D(make_curva2(ct2), (-pi / 2, pi / 2, 100), width=0.5) curva2.attachField( "tangente", make_tang2(ct2)).setLengthFactor(1).setWidthFactor(.5) curva2.fields['tangente'].show() tangentes2.append(curva2.fields['tangente']) self.addChild(curva) self.addChild(curva2) def animaTangentes(n): for tang in tangentes + tangentes2: tang.animateArrow(int(n)) a1 = Animation(animaTangentes, (6000, 0, 99), times=1) self.setupAnimations([a1]) Slider(rangep=('u', 0, 99, 0, 100), func=animaTangentes, parent=self)
def __init__(self): Page.__init__( self, u"Construcción de un vector del campo de Morse sobre el toro") def coreTorusAt(p): dyz = sqrt(p[1]**2 + p[2]**2) return Vec3(0.0, a * p[1] / dyz, a * p[2] / dyz) def unitNormalToTorusAt(p): core = coreTorusAt(p) p_core = p - core dp_core = p_core.length() return p_core / dp_core def projAtTorus(p): core = coreTorusAt(p) p_core = p - core factor = 1.005 * b / p_core.length( ) #un poco más de 1 para que se vea mejor... return core + factor * p_core def valMorseFieldAt(p): n = unitNormalToTorusAt(p) gdotn = -g * n[2] return Vec3(gdotn * n[0], gdotn * n[1], g + gdotn * n[2]) def nextPoint(p, dt): return projAtTorus(p + dt * valMorseFieldAt(p)) class CurveVectorField: def __init__(self, c): self.curve = c def basePoint(self, t): return self.curve[int(t)] def endPoint(self, t): return self.curve[int(t)] + valMorseFieldAt(self.curve[int(t)]) class CurveNormalField: def __init__(self, c): self.curve = c def basePoint(self, t): return self.curve[int(t)] def endPoint(self, t): return self.curve[int(t)] + unitNormalToTorusAt( self.curve[int(t)]) class CurveGravityField: def __init__(self, c): self.curve = c def basePoint(self, t): return self.curve[int(t)] def endPoint(self, t): return self.curve[int(t)] + Vec3(0, 0, g) curves = [] vectorial_fields_curves = [] vectorial_fields_curves_bk = [] dtheta = pi / 10.0 nrot = -4 points_down_curve = [] points_up_curve = [] q = Vec3(b * cos(nrot * dtheta), a + b * sin(nrot * dtheta), 0.0) # calculo empezando enmedio del toro for n in range(0, 100): p = projAtTorus(q) v = valMorseFieldAt(p) if v.length() < 0.01: break points_down_curve.append(p) points_up_curve.append(Vec3(p[0], p[1], -p[2])) q = nextPoint(p, 0.05) #Tangent Plane p = projAtTorus(q) p[2] = -p[2] v = valMorseFieldAt(p) u = v.cross(unitNormalToTorusAt(p)) tangent_plane = Plane(_1(200, 200, 200), p, v + p, u + p) points_down_curve.reverse() # recorrer de arriba a enmedio points_down_curve.pop( ) # quitar los puntos de enmedio, repetidos en las listas points_down_curve.extend(points_up_curve) # unir listas points_down_curve.reverse() curve = Line(points_down_curve, width=2.5) curves.append(curve) cvf = CurveVectorField(curve) vectorial_fields_curves_bk.append(cvf) arrow = AnimatedArrow(cvf.basePoint, cvf.endPoint) arrow.setDiffuseColor(_1(220, 40, 200)) arrow.setWidthFactor(0.48) arrow.add_tail(0.025) vectorial_fields_curves.append(arrow) cnf = CurveNormalField(curve) vectorial_fields_curves_bk.append(cnf) arrown = AnimatedArrow(cnf.basePoint, cnf.endPoint) arrown.setDiffuseColor(_1(220, 240, 20)) arrown.setWidthFactor(0.4) #arrown.add_tail( 0.025 ) vectorial_fields_curves.append(arrown) cgf = CurveGravityField(curve) vectorial_fields_curves_bk.append(cgf) arrowg = AnimatedArrow(cgf.basePoint, cgf.endPoint) arrowg.setDiffuseColor(_1(10, 240, 20)) arrowg.setWidthFactor(0.4) #arrowg.add_tail( 0.025 ) vectorial_fields_curves.append(arrowg) self.addChildren(curves) self.addChildren(vectorial_fields_curves) self.addChild(tangent_plane) def setSyncParam(t): for i in range(0, len(vectorial_fields_curves)): #curve = curves[i] if t < len(curves[0].getPoints()): vec_field = vectorial_fields_curves[i] vec_field.animateArrow(t) q = (curves[0])[int(t)] p = projAtTorus(q) v = valMorseFieldAt(p) u = v.cross(unitNormalToTorusAt(p)) tangent_plane.setPoints(p, v + p, u + p) Slider(rangep=('t', 0, 198, 1, 199), func=setSyncParam, duration=8000, parent=self) # T(u,v) def toroParam1(u, v): return (b * sin(u), (a + b * cos(u)) * cos(v), (a + b * cos(u)) * sin(v)) def toroParam(u, v): return Vec3(b * sin(u), (a + b * cos(u)) * cos(v), (a + b * cos(u)) * sin(v)) paratoro = ParametricPlot3D(toroParam1, (0, 2 * pi, 150), (0, 2 * pi, 100)) paratoro.setTransparency(0.25) paratoro.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) paratoro.setTransparencyType(SoTransparencyType.SCREEN_DOOR) paratoro.setDiffuseColor(_1(68, 28, 119)) self.addChild(paratoro)
def __init__(self): Page.__init__(self, u"Campo de Morse sobre el toro") a = 2.0 b = 1.0 g = -1.25 # T(u,v) def toroParam1(u,v): return (b*sin(u),(a+b*cos(u))*cos(v),(a+b*cos(u))*sin(v)) def toroNormal(u,v): coef = b * ( a + b * cos(u) ) return Vec3( coef * sin(u), coef * cos(u) * cos(v), coef * cos(u) * sin(v) ) def toroMorse(u,v): #coef = -b * ( a + b * cos(u) ) coef2 = -g * cos(u) * sin(v) return Vec3( coef2 * sin(u), coef2 * cos(u) * cos(v), g + coef2 * cos(u) * sin(v) ) paratoro = ParametricPlot3D(toroParam1, (0,2*pi,150),(0,2*pi,100)) paratoro.setTransparency(0.25) paratoro.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) paratoro.setDiffuseColor(_1(68, 28, 119)) self.addChild(paratoro) def make_curva(c): return lambda t: toroParam1(c,t) def make_curva2(c): return lambda t: toroParam1(c,-t) def make_tang(c): return lambda t: toroMorse(c,t) def make_tang2(c): return lambda t: toroMorse(c,-t) tangentes = [] tangentes2 = [] ncurves = 12 for c in range(0,ncurves+1): ## -1 < ct < 1 ct = c/float(ncurves) * 2*pi #curva = Curve3D(make_curva(ct),(-pi/2,pi/2,100), width=0.5) curva = Curve3D(make_curva(ct),(pi/2,3*pi/2,100), width=0.5) curva.attachField("tangente", make_tang(ct)).setLengthFactor(1).setWidthFactor(.5) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) ### ct2 = c/float(ncurves) * 2*pi #curva2 = Curve3D(make_curva2(ct2),(pi/2,3*pi/2,100), width=0.5) curva2 = Curve3D(make_curva2(ct2),(-pi/2,pi/2,100), width=0.5) curva2.attachField("tangente", make_tang2(ct2)).setLengthFactor(1).setWidthFactor(.5) curva2.fields['tangente'].show() tangentes2.append(curva2.fields['tangente']) self.addChild(curva) self.addChild(curva2) def animaTangentes(n): for tang in tangentes+tangentes2: tang.animateArrow(int(n)) a1 = Animation(animaTangentes, (6000, 0, 99), times=1) self.setupAnimations([a1]) Slider(rangep=('u', 0,99,0,100),func=animaTangentes, parent=self)
def __init__(self): Page.__init__(self, u"Toro") a = 1 b = 0.5 def toroParam1(u, v): return ((a + b * cos(v)) * cos(u), (a + b * cos(v)) * sin(u), b * sin(v)) toro = ParametricPlot3D(toroParam1, (0, 2 * pi, 150), (0, 2 * pi, 100)) toro.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) toro.setTransparency(.4) # delta = 0 # p_eli = Sphere((.9571067805, .9571067805, .35+delta),0.02,visible=True) # p_eli.setColor( _1(194,38,69)) # p_eli.setShininess(1) # # p_par = Sphere ((-0.7071067810, 0.7071067810, 0.5+delta),0.02,visible=True) # p_par.setColor( _1(240,108,21)) # p_par.setShininess(1) # # p_hyp = Sphere ((0, -0.6464466095, .3535+delta),0.02,visible=True) # p_hyp.setColor( _1(78,186,69)) # p_hyp.setShininess(1) def toro_u(u, v): return Vec3(-(a + b * cos(v)) * sin(u), (a + b * cos(v)) * cos(u), 0) def toro_v(u, v): return Vec3(-b * sin(v) * cos(u), -b * sin(v) * sin(u), b * cos(v)) ## plano parabólico ptopar = (0, pi / 2) plane_par = TangentPlane2(toroParam1, toro_u, toro_v, ptopar, _1(252, 250, 225)) plane_par.baseplane.setTransparency(0) def curvaPlana(t): return plane_par.planeParam(cos(t), sin(t) + 1) curva = Curve3D(curvaPlana, (-pi, 0, 30), color=(1, 0, 0), width=2) self.addChild(toro) self.addChild(plane_par) self.addChild(curva) def animaCurva1(n): def curva(t): return (t * 2 * pi, pi / 2) plane_par.setLocalOrigin(curva(n / 100.)) def animaCurva2(n): def curva(t): return (0, pi / 2 - t * (2 * pi + pi / 2)) plane_par.setLocalOrigin(curva(n / 100.)) def animaCurva3(n): def curva(t): return (t * 2 * pi, 0) plane_par.setLocalOrigin(curva(n / 100.)) a1 = Animation(animaCurva1, (6000, 0, 100)) a2 = Animation(animaCurva2, (6000, 0, 100)) a3 = Animation(animaCurva3, (6000, 0, 100)) self.setupAnimations([a1, a2, a3])
def __init__(self): Page.__init__(self, u"Planos osculador, normal y rectificante") tmin = -2 * pi tmax = 2 * pi ## ============================================ sq2 = 2**0.5 inv_sq2 = (1. / sq2) def helix(s): s_times_sq2 = inv_sq2 * s return Vec3(cos(s_times_sq2), sin(s_times_sq2), s_times_sq2) def tangent(s): s_div_sq2 = s / sq2 return Vec3(-inv_sq2 * sin(s_div_sq2), inv_sq2 * cos(s_div_sq2), inv_sq2) def normal(s): s_div_sq2 = s / sq2 return Vec3(-cos(s_div_sq2), -sin(s_div_sq2), 0) def bi_normal(s): s_div_sq2 = s / sq2 return Vec3(inv_sq2 * sin(s_div_sq2), -inv_sq2 * cos(s_div_sq2), inv_sq2) curve = Curve3D(helix, (tmin, tmax, 100), _1(206, 75, 150), 2) self.addChild(curve) #======================================================================= # Vectors #======================================================================= field_tangent = curve.attachField("tangent", tangent).show() field_normal = curve.attachField("normal", normal).show() field_binormal = curve.attachField("binormal", bi_normal).show() #======================================================================= # Planes #======================================================================= def get_points(v1, v2): return v2.p1, v1.p2, v2.p2 color = (.5, .5, .5) plane_osculating = Plane(color, *get_points(field_tangent, field_normal)) plane_normal = Plane(color, *get_points(field_normal, field_binormal)) plane_rectifying = Plane(color, *get_points(field_binormal, field_tangent)) self.addChildren([plane_osculating, plane_normal, plane_rectifying]) def update_planes(n): plane_osculating.setPoints( *get_points(field_tangent, field_normal)) plane_normal.setPoints(*get_points(field_normal, field_binormal)) plane_rectifying.setPoints( *get_points(field_binormal, field_tangent)) r = (5000, 0, len(curve) - 1) animation = Animatable(update_planes, r) self.setupAnimations([ AnimationGroup( [field_tangent, field_normal, field_binormal, animation], r) ])