Exemple #1
0
    def __init__(self):
        #u"""x^2 + y^2 + z^2 = 1"""

        super(EsferaCasquetes, self).__init__(u"Otro atlas de la esfera")

        r = .998
        esf = ParametricPlot3D(
            lambda t, f:
            (r * sin(t) * cos(f), r * sin(t) * sin(f), r * cos(t)),
            (0, pi, 70), (0, 2 * pi, 70))
        esf.setDiffuseColor(_1(99, 136, 63))
        esf.setSpecularColor(_1(99, 136, 63))

        pars = [
            lambda u, v, t1: (u, v, 1.5 - t1 * (1.5 - sqrt(1 - u**2 - v**2))),
            lambda u, v, t2: (u, v, -1 - t2 * (-1 + sqrt(1 - u**2 - v**2))),
            lambda u, v, t3: (u, 1.5 - t3 * (1.5 - sqrt(1 - u**2 - v**2)), v),
            lambda u, v, t4: (u, -1.5 - t4 *
                              (-1.5 + sqrt(1 - u**2 - v**2)), v),
            lambda u, v, t5: (1.5 - t5 * (1.5 - sqrt(1 - u**2 - v**2)), u, v),
            lambda u, v, t6, : (-1.5 - t6 *
                                (-1.5 + sqrt(1 - u**2 - v**2)), u, v)
        ]

        d = .7
        colores = [(0, 0, 1), (0, 0, 1), (0, 1, 0), (0, 1, 0), (1, 0, 0),
                   (1, 0, 0)]
        planos = [
            ParametricPlot3D(par, (-d, d, 40), (-d, d, 40)).setLinesVisible(
                True).setMeshVisible(False).setMeshDiffuseColor(colores[i])
            for i, par in enumerate(pars)
        ]

        baseplane = BasePlane()
        baseplane.setHeight(-1.005)
        baseplane.setRange((-2, 2, 7))
        self.addChild(esf)
        for p in planos:
            self.addChild(p)
        self.addChild(baseplane)

        ## no queremos los controles
        for i, plano in enumerate(planos):
            plano.parameters['t%d' % (i + 1)].hide()

        anims = [
            plano.parameters['t%d' % (i + 1)].asAnimation()
            for i, plano in enumerate(planos)
        ]
        self.setupAnimations(anims)
Exemple #2
0
    def __init__(self):
        super(Catenoide, self).__init__(
            u"Cortamos una catenoide para obtener parte de una helicoide")
        self.camera_position = (8.2, 8.2, 8.2)
        self.camera_viewAll = False

        def param(u, v, t):
            t2 = pi / 2 - t
            x = cos(t2) * sinh(v) * sin(u) + sin(t2) * cosh(v) * cos(u)
            y = -cos(t2) * sinh(v) * cos(u) + sin(t2) * cosh(v) * sin(u)
            z = u * cos(t2) + v * sin(t2)
            return x, y, z

        cat = ParametricPlot3D(param, (-pi, pi, 60), (-2, 2))
        ht = cat.getParameter('t')
        ht.timeline.setDuration(3000)
        ht.updateRange((0, pi / 2, 0))
        cat.setVerticesPerColumn(2)

        cat.setAmbientColor(_1(4, 73, 143))
        cat.setDiffuseColor(_1(4, 73, 143))
        cat.setSpecularColor(_1(4, 73, 143))

        s = Slider(rangep=('z', 2, 60, 2, 59),
                   func=cat.setVerticesPerColumn,
                   duration=3000,
                   parent=self)

        self.addChild(cat)
        params = [s, ht]
        ## no queremos los controles
        for p in params:
            p.hide()
        anims = [p.asAnimation() for p in params]
        self.setupAnimations(anims)
Exemple #3
0
    def __init__(self):
        super(Helicoide, self).__init__(
            u"Isometría local entre una helicoide y una catenoide")
        self.camera_position = (8.2, 8.2, 8.2)
        self.camera_viewAll = False

        def param(u, v, t):
            x = cos(t) * sinh(v) * sin(u) + sin(t) * cosh(v) * cos(u)
            y = -cos(t) * sinh(v) * cos(u) + sin(t) * cosh(v) * sin(u)
            z = u * cos(t) + v * sin(t)
            return x, y, z

        helic1 = ParametricPlot3D(param, (-pi, pi, 60), (-2, 2))
        ht = helic1.getParameter('t')
        ht.timeline.setDuration(3000)
        ht.updateRange((0, pi / 2, 0))
        helic1.setVerticesPerColumn(2)

        helic1.setAmbientColor(_1(202, 78, 70))
        helic1.setDiffuseColor(_1(202, 78, 70))
        helic1.setSpecularColor(_1(202, 78, 70))

        s = Slider(rangep=('z', 2, 60, 2, 59),
                   func=helic1.setVerticesPerColumn,
                   duration=3000,
                   parent=self)
        self.addChild(helic1)

        params = [s, ht]
        ## no queremos los controles
        for p in params:
            p.hide()
        anims = [p.asAnimation() for p in params]
        self.setupAnimations(anims)
Exemple #4
0
    def __init__(self):
        super(Mobius,
              self).__init__(u"No orientabilidad de la Banda de Möbius")

        #        self.camera_position = (3.0, 2.8, 2.8)

        def par(u, v):
            return cos(u) + v * cos(u / 2) * cos(u), sin(u) + v * cos(
                u / 2) * sin(u), v * sin(u / 2)

        mobius = ParametricPlot3D(par, (-pi, pi, 60), (-.5, .5, 14))
        mobius.setTransparency(0.5)

        def curva(t):
            return par(t, 0)

        def puntos(u):
            return Vec3(
                cos(u) * sin(u / 2.0),
                sin(u / 2.0) * sin(u), -cos(u / 2.0))

        cm = Curve3D(curva, (-pi, pi, 200), color=_1(255, 255, 255), width=3)
        aceleracion_cm = cm.attachField(
            "aceleracion", puntos).setLengthFactor(1).setWidthFactor(.5)
        aceleracion_cm.animation.setDuration(12000)

        self.addChild(mobius)
        self.addChild(cm)
        self.addChild(Arrow((-1, 0, 0), (0, 0, 0), 0.02))

        self.setupAnimations([aceleracion_cm])
Exemple #5
0
def createEllipsoid(a,b,c):

    par_e = lambda u, v: Vec3(a * sin(v) * cos(u), b * sin(u) * sin(v), c * cos(v))
    e = ParametricPlot3D(par_e, (0, 2*pi, 100), (0, pi, 100))
    e.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND)
    e.setTransparency(0.5)
    e.setDiffuseColor(_1(40, 200, 120))

    return e
Exemple #6
0
def createHyperboloid(a,b):

    par_h = lambda u, v: Vec3(u, v, u**2/(a**2)-v**2/(b**2))
    h = ParametricPlot3D(par_h, (-4, 4, 100), (-4, 4, 100))
    h.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND)
    h.setTransparency(0.5)
    h.setDiffuseColor(_1(220, 200, 80))

    return h
Exemple #7
0
def createTorus(r1,r2):

    par_t = lambda u, v: Vec3((r1 + r2 * cos(v)) * cos(u), (r1 + r2 * cos(v)) * sin(u), r2 * sin(v))
    tor = ParametricPlot3D(par_t, (-pi, pi, 100), (-pi, pi, 100))
    tor.setTransparencyType(SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND)
    tor.setTransparency(0.5)
    tor.setDiffuseColor(_1(180, 220, 200))

    return tor
Exemple #8
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])
Exemple #9
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)
Exemple #10
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)
        ])
Exemple #11
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))])
Exemple #12
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])
Exemple #13
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)
Exemple #14
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])
Exemple #15
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])
Exemple #16
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))])
Exemple #17
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)
Exemple #18
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)
Exemple #19
0
import sys
from math import pi, sin, cos
from PyQt4 import QtGui
from superficie.plots import ParametricPlot3D
from superficie.viewer import MinimalViewer

app = QtGui.QApplication(sys.argv)
viewer = MinimalViewer()

a = 1
b = 0.5
c = .505


def torus(u, v):
    return (a + b * cos(v)) * cos(u), (a + b * cos(v)) * sin(u), b * sin(v)


plot = ParametricPlot3D(torus, (0, 2 * pi, 150), (0, 2 * pi, 100))

viewer.addChild(plot).viewAll().resize(400, 400)
viewer.show()
sys.exit(app.exec_())
Exemple #20
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))
Exemple #21
0
    def __init__(self):
        super(Hiperboloide,self).__init__(u'Secciones normales de un paraboloide hiperbólico<br><br>x<sup>2</sup>/4 - y<sup>2</sup>/9 = z')

        self.showAxis(False)

        hyperboloid = createHyperboloid(2,3)
        self.addChild(hyperboloid)

        normal = Arrow((0,0,0), (0,0,1), 0.03)
        self.addChild(normal)

        class Parabole(object):

            def __init__(self, t=0.0):
                self.param = t

            def __call__(self, s):
                return Vec3(cos(pi_2*self.param)*s, sin(pi_2*self.param)*s, (cos(pi_2*self.param)*s)**2/4 - (sin(pi_2*self.param)*s)**2/9)

            def setParam(self, t):
                self.param = t

        parabole_obj = Parabole()
        curve = Curve3DParam(parabole_obj, (-4.0, 4.0, 200), color=(0.9, 0.2, 0.1), width=6)

        normal_plane_function = lambda u, v: (cos(pi_2*th)*v, sin(pi_2*th)*v, u)
        normal_plane_function.func_globals['th']=0.0
        normal_plane = ParametricPlot3D(normal_plane_function, (-4.1, 4.1), (-4.1, 4.1))
        normal_plane.setTransparency(0.75)
        normal_plane.setTransparencyType(SoTransparencyType.SCREEN_DOOR)
        #normal_plane.animation = normal_plane.parameters['th'].asAnimation()

        VisibleCheckBox("Plano Normal", normal_plane, True, parent=self)

        def basePoint(t):
            return Vec3(0,0,0)

        def endTangentPoint(t):
            s = pi_2*t #/1000.0
            return Vec3(cos(s), sin(s), 0)

        def endCurvaturePoint(t):
            # ||curve'(0)||**2
            s = pi_2*t #/1000.0
            # vn = 1.0
            # ||curve''(0)||
            nn = ((cos(s))**2)/2 - 2*((sin(s))**2)/9
            return Vec3(0, 0, 2.0*nn)

        tangent_arrow = AnimatedArrow(basePoint, endTangentPoint)
        tangent_arrow.setDiffuseColor(_1(20,10,220))

        curvature_arrow = AnimatedArrow(basePoint, endCurvaturePoint)
        curvature_arrow.setDiffuseColor(_1(220,200,20))

        objects = [curve, normal_plane, tangent_arrow, curvature_arrow]
        self.addChildren( objects )

        def setSyncParam(t):
            normal_plane_function.func_globals['th']=t
            normal_plane.updateAll()
            curve.setParam(t)
            tangent_arrow.animateArrow(t)
            curvature_arrow.animateArrow(t)

        Slider(rangep=('t', 0,1.0,0,20),func=setSyncParam, duration=4000, parent=self)
Exemple #22
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])
Exemple #23
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])
Exemple #24
0
    def __init__(self):
        super(Toro3,self).__init__(u'Secciones normales de un toro en un punto hiperbólico')

        self.showAxis(False)

        torus = createTorus(r1, r2)
        self.addChild(torus)

        normal = Arrow((r1-r2,0,0), (r1-r2-1,0,0), 0.03)
        self.addChild(normal)

        class TorusCurve(object):

            def __init__(self, t=0.0):
                self.param = t

            def __call__(self, s):
                param1 = pi_2*self.param #/1000.0
                cosp = cos(param1)
                sinp = sin(param1)
                v = s
                btor = 2.0*v**2 - 20.0
                ctor = v**4 + (16.0 - 36.0*sinp**2)*v**2 + 64.0
                dis = btor**2 - 4.0*ctor
                if dis < 0.0:
                    #v = 0.0
                    u = 4.0
                else:
                    inside = -btor-sqrt(dis)
                    if inside < 0.0:
                        #v = 0.0
                        u = 4.0
                    else:
                        u = sqrt( inside/2.0 )
                return Vec3(u, sinp*v, -cosp*v)

            def setParam(self, t):
                self.param = t

        torusc_obj = TorusCurve()
        curve = Curve3DParam(torusc_obj, (-2.0, 2.0, 200), color=(0.9, 0.2, 0.1), width=6)
        curve.setBoundingBox((-0.05,2.95),(-4.1,4.1),(-1.1,1.1))

        normal_plane_function = lambda u, v: (u, sin(pi_2*tt3)*v, -cos(pi_2*tt3)*v)
        normal_plane_function.func_globals['tt3']=t
        normal_plane = ParametricPlot3D(normal_plane_function, (-4.1, 4.1), (-4.1, 4.1))
        normal_plane.setTransparency(0.75)
        normal_plane.setTransparencyType(SoTransparencyType.SCREEN_DOOR)
        #normal_plane.animation = normal_plane.parameters['tt3'].asAnimation()

        VisibleCheckBox("Plano Normal", normal_plane, True, parent=self)

        def basePoint(t):
            return Vec3(r1-r2,0,0)

        def endTangentPoint(t):
            # ||curve'(0)||
            s = pi_2*t #/1000.0
            #vn = sqrt((b*sin(s))**2 + (c*cos(s))**2)
            return Vec3(r1-r2, -sin(s), cos(s))

        def endCurvaturePoint(t):
            # ||curve'(0)||**2
            #s = pi_2*t/1000.0
            s = t #/1000.0
            #vn = (b*sin(s))**2 + (c*cos(s))**2
            # ||curve''(0)||
            # nn = a
            return Vec3(r1-2*s*r2, 0, 0)

        tangent_arrow = AnimatedArrow(basePoint, endTangentPoint)
        tangent_arrow.setDiffuseColor(_1(20,10,220))

        curvature_arrow = AnimatedArrow(basePoint, endCurvaturePoint)
        curvature_arrow.setDiffuseColor(_1(220,200,20))

        objects = [curve, normal_plane, tangent_arrow, curvature_arrow]
        self.addChildren( objects )

        def setSyncParam(t):
            normal_plane_function.func_globals['tt3']=t
            normal_plane.updateAll()
            curve.setParam(t)
            tangent_arrow.animateArrow(t)
            curvature_arrow.animateArrow(t)

        Slider(rangep=('t', 0,1.0,0,40),func=setSyncParam, duration=4000, parent=self)
Exemple #25
0
    def __init__(self):
        super(Elipsoide2,self).__init__('Secciones normales de un elipsoide en el punto (0,0,1)<br><br>x<sup>2</sup>/9 + y<sup>2</sup>/4 + z<sup>2</sup> = 1')

        self.showAxis(False)

        ellipsoid = createEllipsoid(a, b, c)
        self.addChild(ellipsoid)

        normal = Arrow((0,0,c), (0,0,c+1), 0.03)
        self.addChild(normal)

        class Ellipse(object):

            def __init__(self, t=0.0):
                self.param = t

            def __call__(self, s):
                param1 = pi_2*self.param #/1000.0
                return Vec3(a*cos(param1)*sin(s), b*sin(param1)*sin(s), c*cos(s))

            def setParam(self, t):
                self.param = t

        ellipse_obj = Ellipse()
        curve = Curve3DParam(ellipse_obj, (-3.14, 3.14, 200), color=(0.9, 0.2, 0.1), width=6)

        normal_plane_function = lambda u, v: (a*cos(pi_2*t2)*v, b*sin(pi_2*t2)*v, c*u)
        normal_plane_function.func_globals['t2']=0.0
        normal_plane = ParametricPlot3D(normal_plane_function, (-1.1, 1.1), (-1.1, 1.1))
        normal_plane.setTransparency(0.75)
        normal_plane.setTransparencyType(SoTransparencyType.SCREEN_DOOR)
        #normal_plane.animation = normal_plane.parameters['t2'].asAnimation()

        VisibleCheckBox("Plano Normal", normal_plane, True, parent=self)

        def basePoint(t):
            return Vec3(0,0,c)

        def endTangentPoint(t):
            # ||curve'(0)||
            s = pi_2*t #/1000.0
            vn = sqrt((a*cos(s))**2 + (b*sin(s))**2)
            return Vec3(a*cos(s)/vn, b*sin(s)/vn, c)

        def endCurvaturePoint(t):
            # ||curve'(0)||**2
            s = pi_2*t #/1000.0
            vn = (a*cos(s))**2 + (b*sin(s))**2
            # ||curve''(0)||
            # nn = c
            return Vec3(0, 0, c-2.0*c/vn)

        tangent_arrow = AnimatedArrow(basePoint, endTangentPoint)
        tangent_arrow.setDiffuseColor(_1(20,10,220))

        curvature_arrow = AnimatedArrow(basePoint, endCurvaturePoint)
        curvature_arrow.setDiffuseColor(_1(220,200,20))

        objects = [curve, normal_plane, tangent_arrow, curvature_arrow]
        self.addChildren( objects )

        def setSyncParam(t):
            normal_plane_function.func_globals['t2']=t
            normal_plane.updateAll()
            curve.setParam(t)
            tangent_arrow.animateArrow(t)
            curvature_arrow.animateArrow(t)

        Slider(rangep=('t', 0,1,0,20),func=setSyncParam, duration=4000, parent=self)
Exemple #26
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])
Exemple #27
0
    def __init__(self):
        super(Elipsoide3,self).__init__(u'Secciones normales de un elipsoide un punto umbílico<br><br>x<sup>2</sup>/9 + y<sup>2</sup>/4 + z<sup>2</sup> = 1')

        self.showAxis(False)

        ellipsoid = createEllipsoid(a, b, c)
        self.addChild(ellipsoid)

        # umbilic point U = (px, 0, pz)
        #px = sqrt((a**2-b**2)/(a**2-c**2))
        #pz = sqrt((c**2)*(b**2-c**2)/(a**2-c**2))
        pz = sqrt((c**2-b**2)/(c**2-a**2))
        px = sqrt((a**2)*(b**2-a**2)/(c**2-a**2))

        # gradient in umbilic point U
        nx = 2*px/(a**2)
        nz = 2*pz/(c**2)

        n = sqrt(nx**2+nz**2)

        nx = nx/n
        nz = nz/n

        #print px, pz, px**2/(a**2)+pz**2/(c**2), nx, nz

        normal = Arrow((px,0,pz), (px+nx,0,pz+nz), 0.03)
        self.addChild(normal)

        curvature_arrow = Arrow((px,0,pz), (px-0.5*nx,0,pz-0.5*nz), 0.05)
        curvature_arrow.setDiffuseColor(_1(220,200,20))
        self.addChild(curvature_arrow)

        class Ellipse(object):

            def __init__(self, t=0.0):
                self.param = t

            def __call__(self, s):
                param1 = pi_2*self.param #/1000.0
                cosp = cos(param1)
                sinp = sin(param1)
                A = (nx**2)/9.0 + nz**2
                C = ((nz**2)/9.0 + nx**2)*cosp**2+(sinp**2)/4.0
                B = (16.0/9.0)*nx*nz*cosp
                D = 2.0*(nx*px/9.0 + nz*pz)
                E = 2.0*(nx*pz - nz*px/9.0)*cosp
                #F = 0
                ins_sqrt = A**2 + C**2 + B**2 - 2.0*A*C
                L1 = (A + C + sqrt(ins_sqrt) )/2.0
                L2 = (A + C - sqrt(ins_sqrt) )/2.0
                dis = 4.0*A*C-B**2
                C1 = (B*E-2.0*C*D)/dis
                C2 = (D*B-2.0*A*E)/dis
                detq = (A*(E**2) + C*(D**2) - B*D*E) #/4.0
                aell = sqrt(dis/(L1*detq))/(1.0+sinp*sinp)
                bell = sqrt(dis/(L2*detq))/(1.0+sinp*sinp)
                theta = atan( B/(A-C) )/2.0
                u = aell*cos(s)*cos(theta) - bell*sin(s)*sin(theta) + C1
                v = bell*sin(s)*cos(theta) + aell*cos(s)*sin(theta) + C2
                return Vec3(px+u*nx-cosp*v*nz, sinp*v, pz+u*nz+cosp*v*nx)

            def setParam(self, t):
                self.param = t

        ellipse_obj = Ellipse()
        curve = Curve3DParam(ellipse_obj, (-3.14, 3.14, 200), color=(0.9, 0.2, 0.1), width=6)

        # Rotation Z_Axis=(0,0,1) -> n=(nx,0,nz) (||n||=1)
        # Rot(x,y,z)=(x*nz+z*nx,y,-x*nx+z*nz)
        normal_plane_function = lambda u, v: (px+u*nx-cos(pi_2*t3)*v*nz, sin(pi_2*t3)*v, pz+u*nz+cos(pi_2*t3)*v*nx)
        normal_plane_function.func_globals['t3']=0.0
        normal_plane = ParametricPlot3D(normal_plane_function, (-3.3, 0.1), (-1.9, 4.9))
        normal_plane.setTransparency(0.75)
        normal_plane.setTransparencyType(SoTransparencyType.SCREEN_DOOR)
        normal_plane.setBoundingBox((-3.5,3.5),(-2.1,2.1),(-1.5,1.5))
        #normal_plane.animation = normal_plane.parameters['t3'].asAnimation()

        VisibleCheckBox("Plano Normal", normal_plane, True, parent=self)

        def basePoint(t):
            return Vec3(px,0,pz)

        def endTangentPoint(t):
            # ||curve'(0)||
            s = pi_2*t #/1000.0
            vn = sqrt((nz*cos(s))**2 + (sin(s))**2 + (nx*cos(s))**2)
            return Vec3(px - nz*cos(s)/vn, sin(s)/vn, pz + nx*cos(s)/vn)

        tangent_arrow = AnimatedArrow(basePoint, endTangentPoint)
        tangent_arrow.setDiffuseColor(_1(20,10,220))

        objects = [curve, normal_plane, tangent_arrow]
        self.addChildren( objects )

        def setSyncParam(t):
            normal_plane_function.func_globals['t3']=t
            normal_plane.updateAll()
            curve.setParam(t)
            tangent_arrow.animateArrow(t)
            #curvature_arrow.animateArrow(t)

        Slider(rangep=('t', 0,1,0,20),func=setSyncParam, duration=4000, parent=self)
Exemple #28
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)
Exemple #29
0
    def __init__(self):
        super(Toro1,self).__init__(u'Secciones normales de un toro en un punto elíptico')

        self.showAxis(False)

        torus = createTorus(r1, r2)
        self.addChild(torus)

        normal = Arrow((r1+r2,0,0), (r1+r2+1,0,0), 0.03)
        self.addChild(normal)

        class TorusCurve(object):

            def __init__(self, t=0.0):
                self.param = t

            def __call__(self, s):
                param1 = pi_2*self.param #/1000.0
                cosp = cos(param1)
                sinp = sin(param1)
                u = s #*rot
                btor = 2.0*u**2 + 16.0 - 36.0*sinp**2
                v = sqrt( (-btor+sqrt(btor**2 - 4.0*(u**4-20.0*u**2+64.0)) )/2.0 )
                return Vec3(u, sinp*v, cosp*v)

            def setParam(self, t):
                self.param = t

        torusc_obj = TorusCurve()
        curve = Curve3DParam(torusc_obj, (2.0, 4.0, 200), color=(0.9, 0.2, 0.1), width=6)

        class TorusCurve2(object):

            def __init__(self, t=0.0):
                self.param = t

            def __call__(self, s):
                param1 = pi_2*self.param #/1000.0
                cosp = cos(param1)
                sinp = sin(param1)
                u = s #*rot
                btor = 2.0*u**2 + 16.0 - 36.0*sinp**2
                v = -sqrt( (-btor+sqrt(btor**2 - 4.0*(u**4-20.0*u**2+64.0)) )/2.0 )
                return Vec3(u, sinp*v, cosp*v)

            def setParam(self, t):
                self.param = t

        torusc2_obj = TorusCurve2()
        curve2 = Curve3DParam(torusc2_obj, (2.0, 4.0, 200), color=(0.9, 0.2, 0.1), width=6)

        normal_plane_function = lambda u, v: (u, sin(pi_2*tt1)*v, cos(pi_2*tt1)*v)
        normal_plane_function.func_globals['tt1']=0.0
        normal_plane = ParametricPlot3D(normal_plane_function, (-4.1, 4.1), (-4.1, 4.1))
        normal_plane.setTransparency(0.75)
        normal_plane.setTransparencyType(SoTransparencyType.SCREEN_DOOR)
        #normal_plane.animation = normal_plane.parameters['tt1'].asAnimation()

        VisibleCheckBox("Plano Normal", normal_plane, True, parent=self)

        def basePoint(t):
            return Vec3(r1+r2,0,0)

        def endTangentPoint(t):
            # ||curve'(0)||
            s = pi_2*t #/1000.0
            return Vec3(r1+r2, sin(s), cos(s))

        def endCurvaturePoint(t):
            # ||curve'(0)||**2
            s = t #/1000.0
            #vn = (b*sin(s))**2 + (c*cos(s))**2
            # ||curve''(0)||
            return Vec3(r1+s*(r2-1/r1), 0, 0)

        tangent_arrow = AnimatedArrow(basePoint, endTangentPoint)
        tangent_arrow.setDiffuseColor(_1(20,10,220))

        curvature_arrow = AnimatedArrow(basePoint, endCurvaturePoint)
        curvature_arrow.setDiffuseColor(_1(220,200,20))

        objects = [curve, curve2, normal_plane, tangent_arrow, curvature_arrow]
        self.addChildren( objects )

        def setSyncParam(t):
            normal_plane_function.func_globals['tt1']=t
            normal_plane.updateAll()
            curve.setParam(t)
            curve2.setParam(t)
            tangent_arrow.animateArrow(t)
            curvature_arrow.animateArrow(t)

        Slider(rangep=('t', 0,1.0,0,40),func=setSyncParam, duration=4000, parent=self)
Exemple #30
0
    def __init__(self):
        super(Cilindro,self).__init__('Secciones normales de un cilindro recto circular<br><br>x<sup>2</sup> + z<sup>2</sup> = 1')

        self.showAxis(False)

        cyl = SoCylinder()
        cyl.radius.setValue(1.0)
        cyl.height.setValue(4.0)
        cyl.parts = SoCylinder.SIDES

        light = SoShapeHints()

        mat = SoMaterial()
        mat.emissiveColor = _1(80, 120, 200)
        mat.diffuseColor = _1(80, 120, 200)
        mat.transparency.setValue(0.5)

        sep = SoSeparator()
        sep.addChild(light)
        sep.addChild(mat)
        sep.addChild(cyl)

        self.addChild(sep)

        normal = Arrow((0,0,1), (0,0,2), 0.03)
        self.addChild(normal)

        class CylCurve(object):

            def __init__(self, t=0.0):
                self.param = t

            def __call__(self, s):
                #pi_2*self.param/1000.0
                return Vec3(cos(s), tan(pi_2*self.param) * cos(s), sin(s))

            def setParam(self, t):
                self.param = t

        cylc_obj = CylCurve()
        curve = Curve3DParam(cylc_obj, (-3.14, 3.14, 200), color=(0.9, 0.2, 0.1), width=6)
        curve.setBoundingBox((-3.1,3.1),(-3.1,3.1),(-3.1,3.1))
# Ojo! No basta con "acotar", la vista se recalcula con todo el objeto...

        normal_plane_function = lambda u, v: (cos(pi_2*tc)*v, sin(pi_2*tc)*v, u)
        normal_plane_function.func_globals['tc']=0.0
        normal_plane = ParametricPlot3D(normal_plane_function, (-1.1, 1.1), (-2.1, 2.1))
        normal_plane.setTransparency(0.75)
        normal_plane.setTransparencyType(SoTransparencyType.SCREEN_DOOR)
        #normal_plane.animation = normal_plane.parameters['tc'].asAnimation()

        VisibleCheckBox("Plano Normal", normal_plane, True, parent=self)

        def basePoint(t):
            return Vec3(0,0,1)

        def endTangentPoint(t):
            s = pi_2*t #/1000.0
            return Vec3(cos(s), sin(s), 1)

        def endCurvaturePoint(t):
            return Vec3(0, 0, 0.9-cos(pi_2*t)) #/1000.0

        tangent_arrow = AnimatedArrow(basePoint, endTangentPoint)
        tangent_arrow.setDiffuseColor(_1(20,10,220))

        curvature_arrow = AnimatedArrow(basePoint, endCurvaturePoint)
        curvature_arrow.setDiffuseColor(_1(220,200,20))

        objects = [curve, normal_plane, tangent_arrow, curvature_arrow]
        self.addChildren( objects )

        def setSyncParam(t):
            normal_plane_function.func_globals['tc']=t
            normal_plane.updateAll()
            curve.setParam(t)
            tangent_arrow.animateArrow(t)
            curvature_arrow.animateArrow(t)

        Slider(rangep=('t', 0,0.99,0,20),func=setSyncParam, duration=4000, parent=self)