Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
    def __init__(self):
        Page.__init__(self, u"Hélice circular, curvatura y torsión<br><br>(cos s/&radic;2, sen s/&radic;2, s/&radic;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)) ])
Пример #5
0
    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))])
Пример #6
0
    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)])
Пример #7
0
    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)
        ])
Пример #8
0
    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)
Пример #9
0
    def __init__(self):
        Page.__init__(self, u"Exponencial")
        self.showAxis(True)
        self.axis_z.setVisible(False)

        def curve(t): return Vec3(exp(t) * cos(t), exp(t) * sin(t), exp(t))
        def derivada(t): return Vec3(exp(t) * cos(t) - exp(t) * sin(t), exp(t) * cos(t) + exp(t) * sin(t), exp(t))
        curva1 = Curve3D(curve, (-pi, 1 * pi, 200), width=2)
        self.addChild(curva1)
        curva1.derivative = derivada
        curva1.tangent_vector.show()
        self.setupAnimations([curva1.tangent_vector])
Пример #10
0
    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)
Пример #11
0
    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])
Пример #12
0
 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)
Пример #13
0
 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)
Пример #14
0
    def __init__(self):
        Page.__init__(
            self,
            u"Hélice circular reflejada<br><br>(cos s/&radic;2, sen s/&radic;2, -s/&radic;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))])
Пример #15
0
    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])
Пример #16
0
 def __init__(self):
     Page.__init__(self, u"Curva cúbica alabeada<br><br>&alpha;(t)=(t,t<sup>2</sup>,t<sup>3</sup>)")
     self.camera_position = (5, 5, 5)
     self.camera_viewAll = True
     self.setupPlanes()
     c = lambda t: Vec3(t, t ** 2, t ** 3)
     altura = -1
     curva = Curve3D(c, (-1, 1, 100), width=5, nvertices=1)
     lyz = curva.project(x=altura, color=(0, 1, 1), width=3, nvertices=1)
     lxz = curva.project(y=altura, color=(1, 0, 1), width=3, nvertices=1)
     lxy = curva.project(z=altura, color=(1, 1, 0), width=3, nvertices=1)
     curvas = [curva, lxy, lxz, lyz]
     self.showAxis(False)
     self.addChildren(curvas)
     self.setupAnimations([ AnimationGroup(curvas, (5000,0,len(curva)-1)) ])
Пример #17
0
    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])
Пример #18
0
    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)
Пример #19
0
    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)
Пример #20
0
    def __init__(self):
        Page.__init__(
            self,
            u"Campo sin singularidades en el plano<br><br>(x,y) &rarr; (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])
Пример #21
0
    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])
Пример #22
0
    def __init__(self):
        Page.__init__(
            self,
            u"Hélice circular, curvatura y torsión<br><br>(cos s/&radic;2, sen s/&radic;2, s/&radic;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))
        ])
Пример #23
0
    def __init__(self):
        "x^2 + y^2 = z^2"
        Page.__init__(self, u"Semicono de revolución<br><br>F(&theta;,&rho;)=(&theta;,&rho;,&pi;/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)
Пример #24
0
    def __init__(self):
        Page.__init__(self, u"Exponencial")
        self.showAxis(True)
        self.axis_z.setVisible(False)

        def curve(t):
            return Vec3(exp(t) * cos(t), exp(t) * sin(t), exp(t))

        def derivada(t):
            return Vec3(
                exp(t) * cos(t) - exp(t) * sin(t),
                exp(t) * cos(t) + exp(t) * sin(t), exp(t))

        curva1 = Curve3D(curve, (-pi, 1 * pi, 200), width=2)
        self.addChild(curva1)
        curva1.derivative = derivada
        curva1.tangent_vector.show()
        self.setupAnimations([curva1.tangent_vector])
Пример #25
0
    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)
Пример #26
0
    def __init__(self):
        Page.__init__(self, u"Campo sin singularidades en el plano<br><br>(x,y) &rarr; (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])
Пример #27
0
 def __init__(self):
     Page.__init__(
         self,
         u"Curva cúbica alabeada<br><br>&alpha;(t)=(t,t<sup>2</sup>,t<sup>3</sup>)"
     )
     self.camera_position = (5, 5, 5)
     self.camera_viewAll = True
     self.setupPlanes()
     c = lambda t: Vec3(t, t**2, t**3)
     altura = -1
     curva = Curve3D(c, (-1, 1, 100), width=5, nvertices=1)
     lyz = curva.project(x=altura, color=(0, 1, 1), width=3, nvertices=1)
     lxz = curva.project(y=altura, color=(1, 0, 1), width=3, nvertices=1)
     lxy = curva.project(z=altura, color=(1, 1, 0), width=3, nvertices=1)
     curvas = [curva, lxy, lxz, lyz]
     self.showAxis(False)
     self.addChildren(curvas)
     self.setupAnimations(
         [AnimationGroup(curvas, (5000, 0, len(curva) - 1))])
Пример #28
0
    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)
Пример #29
0
    def __init__(self):
        Page.__init__(
            self,
            u"Otro campo en el paraboloide hiperbólico sin singularidades<br><br>(x,y) &rarr; (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])
Пример #30
0
    def __init__(self):
        "x^2 + y^2 = z^2"
        Page.__init__(
            self,
            u"Semicono de revolución<br><br>F(&theta;,&rho;)=(&theta;,&rho;,&pi;/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)
Пример #31
0
    def __init__(self):
        Page.__init__(self, u"Hélice circular reflejada<br><br>(cos s/&radic;2, sen s/&radic;2, -s/&radic;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)) ])
Пример #32
0
    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))])
Пример #33
0
    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)
        ])
Пример #34
0
    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)
Пример #35
0
    def __init__(self):
        Page.__init__(self, u"Otro campo en el paraboloide hiperbólico sin singularidades<br><br>(x,y) &rarr; (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])
Пример #36
0
    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)
Пример #37
0
    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)
Пример #38
0
    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)
Пример #39
0
    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)
        ])
Пример #40
0
    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)
Пример #41
0
    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)
Пример #42
0
    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)
Пример #43
0
    def __init__(self, parent=None):
        Page.__init__(self, u"Paralelos y círculos máximos de la esfera")
        self.showAxis(False)

        pmin = 0
        pmax = 2 * pi
        r2 = 3.
        l = -1

        def puntos2(t):
            return Vec3(-cos(t), -sin(t), 0)

        def make_circulo(t):
            return partial(par_esfera, t)

        par_esfera = lambda t, f: Vec3(sin(t) * cos(f), sin(t) * sin(f), cos(t))
        par_circulo = lambda f: Vec3(sin(t) * cos(f), sin(t) * sin(f), cos(t))
        par_circulo_der = lambda f: Vec3(-cos(f) * sin(t), -sin(t) * sin(f), 0)
        par_circulo_maximo = make_circulo(pi / 2)

        esf = ParametricPlot3D(par_esfera, (0, pi, 100), (0, 2 * pi, 120))
        esf.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND)
        esf.setTransparency(0.3).setDiffuseColor(_1(68, 28, 119)).setSpecularColor(_1(99, 136, 63))
        VisibleCheckBox("esfera", esf, True, parent=self)
        self.addChild(esf)

        cm = Curve3D(par_circulo_maximo, (pmin, pmax, 200), color=_1(255, 255, 255))
        self.addChild(cm)
        aceleracion_cm = cm.attachField("aceleracion", puntos2).show().setLengthFactor(.98).setWidthFactor(.3)

        tini=1.0472
        par_circulo.func_globals['t'] = tini

        par = Curve3D(par_circulo, (pmin, pmax, 200), color=_1(255, 221, 0))
        self.addChild(par)
        aceleracion_par = par.attachField("aceleracion", par_circulo_der).show().setLengthFactor(1).setWidthFactor(.3)

        circle_2 = SimpleSphere(Vec3(0, 0, cos(tini)), radius=.02)
        circle_2_tr = circle_2.getByName("Translation")

        self.addChild(circle_2)
        self.addChild(SimpleSphere(Vec3(0, 0, 0), radius=.02))

        ## los meridianos
        sep = SoSeparator()
        mer = Curve3D(lambda t: (0, .99 * cos(t), .99 * sin(t)), (pmin, pmax, 100), color=_1(18, 78, 169))
        for i in range(24):
            sep.addChild(rot(2 * pi / 24))
            sep.addChild(mer.root)
        self.addChild(sep)

        # the sphere rotation axis
        self.addChild(Line([(0, 0, -1.2), (0, 0, 1.2)], width=2))

        def test(t):
            par_circulo.func_globals['t'] = t
            par.updatePoints()
            circle_2_tr.translation = (0, 0, cos(t))

        Slider(('t', 0.1, pi-.1, tini, 100), test, duration=4000, parent=self)
        self.setupAnimations([aceleracion_cm, aceleracion_par])
Пример #44
0
    def __init__(self):
        Page.__init__(
            self,
            u"Campo en el paraboloide hiperbólico con una singularidad<br><br>(x,y) &rarr; (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))
Пример #45
0
    def __init__(self):
        """x^2 - y^2 - z = 0"""
        Page.__init__(self, u"Paraboloide hiperbólico<br><br>x<sup>2</sup>/a<sup>2</sup> - y<sup>2</sup>/b<sup>2</sup> = z")

        z = 1.5

        def fn(x, y):
            return x ** 2 - y ** 2 + z

        def polar(function):
            def polar_fn(r, t):
                x = r * cos(t)
                y = r * sin(t)
                return x, y, function(x, y)

            return polar_fn

        paraboloid = ParametricPlot3D(polar(fn), (.001, 1, 20), (0, 2 * pi, 60))

        paraboloid. \
            setAmbientColor(_1(145, 61, 74)). \
            setDiffuseColor(_1(127, 119, 20)). \
            setSpecularColor(_1(145, 61, 74))

        base_plane = BasePlane()
        base_plane.setHeight(0)
        base_plane.setRange((-2, 2, 7))

        ## the hiperbolic paraboloid in parametric form
        def fn_par(x,y): return Vec3(x, y, x ** 2 - y ** 2 + z)

        ## its derivatives
        def fn_x(x,y): return Vec3(1, 0, 2 * x)

        def fn_y(x,y): return Vec3(0, 1, -2 * y)

        tangent_plane = TangentPlane2(fn_par, fn_x, fn_y, (0, 0), _1(252, 250, 225))
        tangent_plane.setRange((-1.2, 1.2, 7))

        self.addChild(paraboloid)
        self.addChild(base_plane)
        self.addChild(tangent_plane)

        def spiral(t):
            c = t / (2 * pi)
            t2 = t * 2
            return c * cos(t2), c * sin(t2)

        animate_points = 200

        def animate_plane(n):
            tangent_plane.setLocalOrigin(spiral(2 * pi * n / float(animate_points)))

        def animate_plane_2(t):
            tangent_plane.setLocalOrigin(spiral(t))

        a1 = Animation(animate_plane, (10000, 0, animate_points))

        Slider(('t', 0, 2 * pi, 0, animate_points), animate_plane_2, duration=10000, parent=self)

        self.setupAnimations([a1])
Пример #46
0
    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)
Пример #47
0
    def __init__(self, parent=None):
        Page.__init__(self, u"Paralelos y círculos máximos de la esfera")
        self.showAxis(False)

        pmin = 0
        pmax = 2 * pi
        r2 = 3.
        l = -1

        def puntos2(t):
            return Vec3(-cos(t), -sin(t), 0)

        def make_circulo(t):
            return partial(par_esfera, t)

        par_esfera = lambda t, f: Vec3(
            sin(t) * cos(f),
            sin(t) * sin(f), cos(t))
        par_circulo = lambda f: Vec3(sin(t) * cos(f), sin(t) * sin(f), cos(t))
        par_circulo_der = lambda f: Vec3(-cos(f) * sin(t), -sin(t) * sin(f), 0)
        par_circulo_maximo = make_circulo(pi / 2)

        esf = ParametricPlot3D(par_esfera, (0, pi, 100), (0, 2 * pi, 120))
        esf.setTransparencyType(
            SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND)
        esf.setTransparency(0.3).setDiffuseColor(_1(68, 28,
                                                    119)).setSpecularColor(
                                                        _1(99, 136, 63))
        VisibleCheckBox("esfera", esf, True, parent=self)
        self.addChild(esf)

        cm = Curve3D(par_circulo_maximo, (pmin, pmax, 200),
                     color=_1(255, 255, 255))
        self.addChild(cm)
        aceleracion_cm = cm.attachField(
            "aceleracion",
            puntos2).show().setLengthFactor(.98).setWidthFactor(.3)

        tini = 1.0472
        par_circulo.func_globals['t'] = tini

        par = Curve3D(par_circulo, (pmin, pmax, 200), color=_1(255, 221, 0))
        self.addChild(par)
        aceleracion_par = par.attachField(
            "aceleracion",
            par_circulo_der).show().setLengthFactor(1).setWidthFactor(.3)

        circle_2 = SimpleSphere(Vec3(0, 0, cos(tini)), radius=.02)
        circle_2_tr = circle_2.getByName("Translation")

        self.addChild(circle_2)
        self.addChild(SimpleSphere(Vec3(0, 0, 0), radius=.02))

        ## los meridianos
        sep = SoSeparator()
        mer = Curve3D(lambda t: (0, .99 * cos(t), .99 * sin(t)),
                      (pmin, pmax, 100),
                      color=_1(18, 78, 169))
        for i in range(24):
            sep.addChild(rot(2 * pi / 24))
            sep.addChild(mer.root)
        self.addChild(sep)

        # the sphere rotation axis
        self.addChild(Line([(0, 0, -1.2), (0, 0, 1.2)], width=2))

        def test(t):
            par_circulo.func_globals['t'] = t
            par.updatePoints()
            circle_2_tr.translation = (0, 0, cos(t))

        Slider(('t', 0.1, pi - .1, tini, 100),
               test,
               duration=4000,
               parent=self)
        self.setupAnimations([aceleracion_cm, aceleracion_par])
Пример #48
0
    def __init__(self):
        Page.__init__(self, u"Toro<br><br>x<sup>4</sup> + y<sup>4</sup> + z<sup>4</sup><br> + 2x<sup>2</sup>y<sup>2</sup> + 2y<sup>2</sup>z<sup>2</sup> + 2z<sup>2</sup>x<sup>2</sup><br> - 10x<sup>2</sup> - 10y<sup>2</sup> + 6z<sup>2</sup> + 9 = 0")
        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)
        b2 = b - .00025
        ## trick: the tangent plane is located in a torus of diameter slightly smaller than the torus; so the
        ## intersection is visible to the naked eye
        def toroParam_delta(u, v):
            return (a + b2 * cos(v)) * cos(u), (a + b2 * cos(v)) * sin(u), b2 * sin(v)
        plane_par = TangentPlane2(toroParam_delta, toro_u, toro_v, ptopar, _1(252, 250, 225))
        plane_par.baseplane.setTransparency(0)
        plane_par.setRange((-.5, .5, 7))

        self.addChild(toro)
        self.addChild(plane_par)

        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])
Пример #49
0
    def __init__(self):
        """x^2 - y^2 - z = 0"""
        Page.__init__(self, u"Paraboloide hiperbólico<br><br>x<sup>2</sup>/a<sup>2</sup> - y<sup>2</sup>/b<sup>2</sup> = z")

        z = 1.5

        def fn(x, y):
            return x ** 2 - y ** 2 + z

        def polar(function):
            def polar_fn(r, t):
                x = r * cos(t)
                y = r * sin(t)
                return x, y, function(x, y)

            return polar_fn

        paraboloid = ParametricPlot3D(polar(fn), (.001, 1, 20), (0, 2 * pi, 60))

        paraboloid. \
            setAmbientColor(_1(145, 61, 74)). \
            setDiffuseColor(_1(127, 119, 20)). \
            setSpecularColor(_1(145, 61, 74))

        base_plane = BasePlane()
        base_plane.setHeight(0)
        base_plane.setRange((-2, 2, 7))

        ## the hiperbolic paraboloid in parametric form
        def fn_par(x,y): return Vec3(x, y, x ** 2 - y ** 2 + z)

        ## its derivatives
        def fn_x(x,y): return Vec3(1, 0, 2 * x)

        def fn_y(x,y): return Vec3(0, 1, -2 * y)

        tangent_plane = TangentPlane2(fn_par, fn_x, fn_y, (0, 0), _1(252, 250, 225))
        tangent_plane.setRange((-1.2, 1.2, 7))

        self.addChild(paraboloid)
        self.addChild(base_plane)
        self.addChild(tangent_plane)

        def spiral(t):
            c = t / (2 * pi)
            t2 = t * 2
            return c * cos(t2), c * sin(t2)

        animate_points = 200

        def animate_plane(n):
            tangent_plane.setLocalOrigin(spiral(2 * pi * n / float(animate_points)))

        def animate_plane_2(t):
            tangent_plane.setLocalOrigin(spiral(t))

        a1 = Animation(animate_plane, (10000, 0, animate_points))

        Slider(('t', 0, 2 * pi, 0, animate_points), animate_plane_2, duration=10000, parent=self)

        self.setupAnimations([a1])
Пример #50
0
 def __init__(self, name):
     Page.__init__(self, name)
     self.camera_position = (0, 0, 13)
     self.camera_point_at = [Vec3(0, 0, 0), Vec3(0, 1, 0)]
     self.showAxis(True)
     self.axis_z.setVisible(False)
Пример #51
0
    def __init__(self):
        Page.__init__(self, u"Campo en el paraboloide hiperbólico con una singularidad<br><br>(x,y) &rarr; (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))
Пример #52
0
    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)
Пример #53
0
    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])
Пример #54
0
 def __init__(self, name):
     Page.__init__(self, name)
     self.camera_position = (0, 0, 13)
     self.camera_point_at = [SbVec3f(0, 0, 0), SbVec3f(0, 1, 0)]
     self.showAxis(True)
     self.axis_z.setVisible(False)
Пример #55
0
 def __init__(self, parent=None):
     Page.__init__(self, "Loxodroma")
     self.creaLoxodroma()
Пример #56
0
    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)
Пример #57
0
    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])
Пример #58
0
    def __init__(self):
        Page.__init__(self, u"Toro<br><br>x<sup>4</sup> + y<sup>4</sup> + z<sup>4</sup><br> + 2x<sup>2</sup>y<sup>2</sup> + 2y<sup>2</sup>z<sup>2</sup> + 2z<sup>2</sup>x<sup>2</sup><br> - 10x<sup>2</sup> - 10y<sup>2</sup> + 6z<sup>2</sup> + 9 = 0")
        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)
        b2 = b - .00025
        ## trick: the tangent plane is located in a torus of diameter slightly smaller than the torus; so the
        ## intersection is visible to the naked eye
        def toroParam_delta(u, v):
            return (a + b2 * cos(v)) * cos(u), (a + b2 * cos(v)) * sin(u), b2 * sin(v)
        plane_par = TangentPlane2(toroParam_delta, toro_u, toro_v, ptopar, _1(252, 250, 225))
        plane_par.baseplane.setTransparency(0)
        plane_par.setRange((-.5, .5, 7))

        self.addChild(toro)
        self.addChild(plane_par)

        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])
Пример #59
0
 def __init__(self, parent=None):
     Page.__init__(self, "Loxodroma")
     self.creaLoxodroma()