def __init__(self): Page.__init__( self, u"Hélice circular reflejada<br><br>(cos s/√2, sen s/√2, -s/√2)" ) self.camera_position = (10, -10, 10) self.showAxis(False) tmin, tmax, npuntos = (-2 * pi, 2 * pi, 200) self.addChild(Cylinder(_1(7, 83, 150), tmax - tmin, 2)) def param1hr(t): return 2 * Vec3(cos(t), sin(t), -t / 3.0) def param2hr(t): return 2 * Vec3(-sin(t), cos(t), -1 / 3.0) def param3hr(t): return 2 * Vec3(-cos(t), -sin(t), 0) espiral = Curve3D(param1hr, (tmin * 1.5, tmax * 1.5, npuntos), color=_1(240, 10, 120)) def param1hc_der(t): return 2 * Vec3(cos(t), sin(t), t / 3.0) espiral_der = Curve3D(param1hc_der, (tmin * 1.5, tmax * 1.5, npuntos), color=_1(20, 240, 240)) tangente = espiral.attachField( "tangente", param2hr).setLengthFactor(1).setWidthFactor(.6) tangente.setRadius(0.06) tangente.setDiffuseColor(_1(20, 240, 20)) normal = espiral.attachField( "normal", param3hr).setLengthFactor(1).setWidthFactor(.6) normal.setRadius(0.06) normal.setDiffuseColor(_1(240, 120, 20)) self.addChild(espiral) self.addChild(espiral_der) plano_xy_par = lambda u, v: Vec3(u, v, 0) plano_xy = ParametricPlot3D(plano_xy_par, (-4, 4, 20), (-4, 4, 20)) plano_xy.setDiffuseColor(_1(200, 200, 200)) plano_xy.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) plano_xy.setTransparency(0.85) self.addChild(plano_xy) self.addChild(Line([(-4, 0, 0), (4, 0, 0)], color=(0.8, 0.8, 0.5))) self.addChild(Line([(0, -4, 0), (0, 4, 0)], color=(0.8, 0.8, 0.5))) self.setupAnimations( [AnimationGroup([tangente, normal], (10000, 0, len(espiral) - 1))])
def __init__(self): super(Mobius, self).__init__(u"No orientabilidad de la Banda de Möbius") # self.camera_position = (3.0, 2.8, 2.8) def par(u, v): return cos(u) + v * cos(u / 2) * cos(u), sin(u) + v * cos( u / 2) * sin(u), v * sin(u / 2) mobius = ParametricPlot3D(par, (-pi, pi, 60), (-.5, .5, 14)) mobius.setTransparency(0.5) def curva(t): return par(t, 0) def puntos(u): return Vec3( cos(u) * sin(u / 2.0), sin(u / 2.0) * sin(u), -cos(u / 2.0)) cm = Curve3D(curva, (-pi, pi, 200), color=_1(255, 255, 255), width=3) aceleracion_cm = cm.attachField( "aceleracion", puntos).setLengthFactor(1).setWidthFactor(.5) aceleracion_cm.animation.setDuration(12000) self.addChild(mobius) self.addChild(cm) self.addChild(Arrow((-1, 0, 0), (0, 0, 0), 0.02)) self.setupAnimations([aceleracion_cm])
def __init__(self): PlanePage.__init__(self, 'Tangent') n_points = 100 delta = .2 # The curve fragments intervals = [ (-pi, -pi / 2 - delta, n_points), (-pi / 2 + delta, pi / 2 - delta, n_points), (pi / 2 + delta, pi, n_points) ] # because intervals is a list of ranges, Curve3D will be a composite of curves curve = Curve3D(lambda t: Vec3(t, tan(t), 0), intervals, width=2).setBoundingBox((-5, 5), (-5, 5)) # add the curve to this page self.addChild(curve) ## asymptotes self.addChild(Line([(-pi / 2, -5, 0), (-pi / 2, 5, 0)], color=(1, .5, .5))) self.addChild(Line([(pi / 2, -5, 0), (pi / 2, 5, 0)], color=(1, .5, .5))) # curve.attachField will create an arrow starting at the curve and ending in the vector given by derivative tangent_vector = curve.attachField("tangent", lambda t: Vec3(1, 1 / cos(t) ** 2, 0)) # by default the arrow doesn't have a tail tangent_vector.add_tail(radius=0.08) # set up the default animations for this page (just the animation for the tangent_vector object in this case) self.setupAnimations([tangent_vector])
def test_Curve3(self): fn = lambda t: (t,0,0) start, end, npoints = (0,1,10) curve = Curve3D(fn,(start,end,npoints)) self.assertEqual(len(curve.lines),1) self.assertEqual(len(curve),npoints) self.assertEqual(tuple(curve[0]), fn(start)) self.assertEqual(tuple(curve[npoints-1]), fn(end))
def __init__(self): Page.__init__(self, u"Campo en la esfera con sólo una singularidad") def make_circulo(t): return partial(par_esfera, t) par_esfera = lambda t, f: 0.99 * Vec3( sin(t) * cos(f), sin(t) * sin(f), cos(t)) esf = ParametricPlot3D(par_esfera, (0, pi, 100), (0, 2 * pi, 120)) esf.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) esf.setTransparency(0.4) esf.setDiffuseColor(_1(68, 28, 119)) VisibleCheckBox("esfera", esf, True, parent=self) self.addChild(esf) def par_curva(c, t): t = tan(t / (4 * pi)) den = c**2 + t**2 + 1 return Vec3(2 * c / den, 2 * t / den, (c**2 + t**2 - 1) / den) def par_tang(c, t): t = tan(t / (4 * pi)) den = (c**2 + t**2 + 1)**2 return Vec3(-2 * c * (2 * t) / den, (2 * (c**2 + t**2 + 1) - 4 * t**2) / den, 4 * t / den) def make_curva(c): return partial(par_curva, c) def make_tang(c): return partial(par_tang, c) tangentes = [] for c in range(-10, 11): ct = tan(c / (2 * pi)) curva = Curve3D(make_curva(ct), (-20, 20, 80), width=1) curva.attachField( "tangente", make_tang(ct)).setLengthFactor(1).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (10000, 0, 79)) self.setupAnimations([a1])
def test_intervals(self): fn = lambda t: (t,0,0) start1, end1, npoints1 = (0,1,5) start2, end2, npoints2 = (2,3,7) ntotal = npoints1 + npoints2 curve = Curve3D(fn, [(start1,end1,npoints1), (start2,end2,npoints2)]) self.assertEqual(len(curve.lines), 2) self.assertEqual(len(curve), ntotal) self.assertEqual(len(curve.points), ntotal) self.assertEqual(len(curve.domainPoints), ntotal) self.assertEqual(tuple(curve[0]), fn(start1)) self.assertEqual(tuple(curve[npoints1 + npoints2-1]), fn(end2))
def __init__(self): Page.__init__(self, u"Otro campo en el toro sin singularidades") a = 1 b = 0.5 def toroParam1(u, v): return ((a + b * cos(v)) * cos(u), (a + b * cos(v)) * sin(u), b * sin(v)) def toro_u(u, v): return Vec3(-(a + b * cos(v)) * sin(u), (a + b * cos(v)) * cos(u), 0) def toro_v(u, v): return Vec3(-b * sin(v) * cos(u), -b * sin(v) * sin(u), b * cos(v)) parab = ParametricPlot3D(toroParam1, (0, 2 * pi, 150), (0, 2 * pi, 100)) parab.setTransparency(0.4) parab.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): return lambda t: toroParam1(t, c) def make_tang(c): return lambda t: toro_u(t, c) tangentes = [] ncurves = 50 for c in range(0, ncurves + 1): ## -1 < ct < 1 ct = c / float(ncurves) * 2 * pi curva = Curve3D(make_curva(ct), (0, 2 * pi, 100), width=1) curva.attachField( "tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (6000, 0, 99)) self.setupAnimations([a1])
def __init__(self): Page.__init__( self, u"Campo sin singularidades en el plano<br><br>(x,y) → (1,0)") par_plano = lambda u, v: Vec3(u, v, 0) def plano_u(u, v): return Vec3(1, 0, 0) def plano_v(u, v): return Vec3(0, 1, 0) parab = ParametricPlot3D(par_plano, (-1, 1, 20), (-1, 1, 20)) parab.setTransparency(0.4) parab.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): return lambda t: par_plano(t, c) def make_tang(c): return lambda t: plano_u(t, c) tangentes = [] ncurves = 30 steps = 70 for c in range(0, ncurves + 1): ## -1 < ct < 1 ct = c / float(ncurves) * 2 - 1 curva = Curve3D(make_curva(ct), (-1, 1, steps), width=1) curva.attachField( "tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (6000, 0, steps - 1)) self.setupAnimations([a1])
def __init__(self): Page.__init__( self, u"Hélice circular, curvatura y torsión<br><br>(cos s/√2, sen s/√2, s/√2)" ) self.camera_position = (10, -10, 10) self.showAxis(False) tmin = -2 * pi tmax = 2 * pi npuntos = 300 self.addChild(Cylinder(_1(185, 46, 61), tmax - tmin, 2)) ## ============================================ # 1 implica primer derivada, 2 implica segunda derivada def param1hc(t): return 2 * Vec3(cos(t), sin(t), t / 3.0) def param2hc(t): return 2 * Vec3(-sin(t), cos(t), 1 / 3.0) def param3hc(t): return 2 * Vec3(-cos(t), -sin(t), 0) def param4hc(t): return 2 * Vec3(sin(t) / 3.0, -cos(t) / 3.0, 1.0) espiral = Curve3D(param1hc, (tmin * 1.5, tmax * 1.5, npuntos), color=_1(255, 255, 255)) tangente = espiral.attachField( "tangente", param2hc).setLengthFactor(1).setWidthFactor(.6) tangente.setRadius(0.06) tangente.setDiffuseColor(_1(20, 240, 20)) normal = espiral.attachField( "normal", param3hc).setLengthFactor(1).setWidthFactor(.6) normal.setRadius(0.06) normal.setDiffuseColor(_1(240, 120, 20)) binormal = espiral.attachField( "binormal", param4hc).setLengthFactor(1).setWidthFactor(.6) binormal.setRadius(0.06) binormal.setDiffuseColor(_1(20, 120, 240)) self.addChild(espiral) self.setupAnimations([ AnimationGroup([tangente, normal, binormal], (10000, 0, len(espiral) - 1)) ])
def __init__(self): 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])
def __init__(self): Page.__init__( self, u"Curva cúbica alabeada<br><br>α(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))])
def __init__(self): Page.__init__( self, u"Otro campo en el paraboloide hiperbólico sin singularidades<br><br>(x,y) → (0, 1, x)" ) par_parab = lambda x, y: Vec3(x, y, x * y) par_tang = lambda x, y: Vec3(0, 1, x) parab = ParametricPlot3D(par_parab, (-1, 1), (-1, 1)) parab.setTransparency(0.4) parab.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): return partial(par_parab, c) def make_tang(c): return partial(par_tang, c) tangentes = [] for c in range(0, 21): ## -1 < ct < 1 ct = 2 * c / 20.0 - 1 curva = Curve3D(make_curva(ct), (-1, 1, 50), width=1) curva.attachField( "tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (6000, 0, 49)) self.setupAnimations([a1])
def __init__(self): Page.__init__(self, u"Campo en la esfera con dos singularidades") par_esfera = lambda u, v: Vec3( sin(u) * cos(v), sin(u) * sin(v), cos(u)) def esfera_u(u, v): return Vec3(cos(u) * cos(v), cos(u) * sin(v), -sin(u)) def esfera_v(u, v): return Vec3(-sin(u) * sin(v), cos(v) * sin(u), 0) parab = ParametricPlot3D(par_esfera, (0, 2, 150), (0, 2 * pi, 100)) parab.setTransparency(0.4) parab.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): return partial(par_esfera, c) def make_tang(c): return partial(esfera_v, c) tangentes = [] curves = [] ncurves = 70 for c in range(0, ncurves + 1): ## -1 < ct < 1 ct = c / float(ncurves) * pi curve = Curve3D(make_curva(ct), (0, 2 * pi, 100), width=1) tangent = curve.attachField( "tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1).show() tangentes.append(tangent) curves.append(curve) self.addChildren(curves) self.setupAnimations([AnimationGroup(tangentes, (6000, 0, 99))])
def __init__(self): Page.__init__( self, u"Campo en el paraboloide hiperbólico con una singularidad<br><br>(x,y) → (0, 1, -k/x<sup>2</sup>)" ) par_parab = lambda x, y: Vec3(x, y, x * y) par_tang = lambda x, y: Vec3(0, 1, x) parab = ParametricPlot3D(par_parab, (-1, 1), (-1, 1)) parab.setTransparency(0.4) parab.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) parab.setDiffuseColor(_1(68, 28, 119)) self.addChild(parab) def make_curva(c): #return partial(par_parab,c) return lambda x: Vec3(x, c / x, c * 1.01) def make_curva_negy(c): #return partial(par_parab,c) return lambda x: Vec3(x, -c / x, -c * 0.99) def make_tang(c): #return partial(par_tang,c) return lambda x: Vec3(x, -c / (x**2), 0.0) / (sqrt(x**2 + c**2 / (x**4))) def make_tang_negy(c): #return partial(par_tang,c) return lambda x: Vec3(x, c / (x**2), 0.0) / (sqrt(x**2 + c**2 / (x**4))) tangentes = [] for c in range(1, 10): ## 0 < ct < 1 ct = c / 10.0 curva = Curve3D(make_curva(ct), (ct, 1.0, 50), width=1.5) curva.attachField( "tangente", make_tang(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente'].show() tangentes.append(curva.fields['tangente']) self.addChild(curva) curva = Curve3D(make_curva_negy(ct), (ct, 1.0, 50), width=1.5) curva.attachField( "tangente_negy", make_tang_negy(ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente_negy'].show() tangentes.append(curva.fields['tangente_negy']) self.addChild(curva) #ct = -1.0 + c/10.0 curva = Curve3D(make_curva(ct), (-ct, -1.0, 50), width=1.5) curva.attachField( "tangente2", make_tang(-ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente2'].show() tangentes.append(curva.fields['tangente2']) self.addChild(curva) curva = Curve3D(make_curva_negy(ct), (-ct, -1.0, 50), width=1.5) curva.attachField( "tangente_negy2", make_tang_negy(-ct)).setLengthFactor(.4).setWidthFactor(.1) curva.fields['tangente_negy2'].show() tangentes.append(curva.fields['tangente_negy2']) self.addChild(curva) def animaTangentes(n): for tang in tangentes: tang.animateArrow(n) a1 = Animation(animaTangentes, (5000, 0, 49)) self.setupAnimations([a1]) self.addChild( Line([(-1, 0, 0.01), (1, 0, 0.01)], color=(1, 1, 1)).setWidth(1.5)) self.addChild( Line([(0, -1, 0.01), (0, 1, 0.01)], color=(1, 1, 1)).setWidth(1.5))
def __init__(self, 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])
def __init__(self): Page.__init__(self, u"Toro") a = 1 b = 0.5 def toroParam1(u, v): return ((a + b * cos(v)) * cos(u), (a + b * cos(v)) * sin(u), b * sin(v)) toro = ParametricPlot3D(toroParam1, (0, 2 * pi, 150), (0, 2 * pi, 100)) toro.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) toro.setTransparency(.4) # delta = 0 # p_eli = Sphere((.9571067805, .9571067805, .35+delta),0.02,visible=True) # p_eli.setColor( _1(194,38,69)) # p_eli.setShininess(1) # # p_par = Sphere ((-0.7071067810, 0.7071067810, 0.5+delta),0.02,visible=True) # p_par.setColor( _1(240,108,21)) # p_par.setShininess(1) # # p_hyp = Sphere ((0, -0.6464466095, .3535+delta),0.02,visible=True) # p_hyp.setColor( _1(78,186,69)) # p_hyp.setShininess(1) def toro_u(u, v): return Vec3(-(a + b * cos(v)) * sin(u), (a + b * cos(v)) * cos(u), 0) def toro_v(u, v): return Vec3(-b * sin(v) * cos(u), -b * sin(v) * sin(u), b * cos(v)) ## plano parabólico ptopar = (0, pi / 2) plane_par = TangentPlane2(toroParam1, toro_u, toro_v, ptopar, _1(252, 250, 225)) plane_par.baseplane.setTransparency(0) def curvaPlana(t): return plane_par.planeParam(cos(t), sin(t) + 1) curva = Curve3D(curvaPlana, (-pi, 0, 30), color=(1, 0, 0), width=2) self.addChild(toro) self.addChild(plane_par) self.addChild(curva) def animaCurva1(n): def curva(t): return (t * 2 * pi, pi / 2) plane_par.setLocalOrigin(curva(n / 100.)) def animaCurva2(n): def curva(t): return (0, pi / 2 - t * (2 * pi + pi / 2)) plane_par.setLocalOrigin(curva(n / 100.)) def animaCurva3(n): def curva(t): return (t * 2 * pi, 0) plane_par.setLocalOrigin(curva(n / 100.)) a1 = Animation(animaCurva1, (6000, 0, 100)) a2 = Animation(animaCurva2, (6000, 0, 100)) a3 = Animation(animaCurva3, (6000, 0, 100)) self.setupAnimations([a1, a2, a3])
def __init__(self): super(Toro, self).__init__(u"Curvas tóricas") tmin, tmax, npuntos = (0, 2 * pi, 3000) a = 1 b = 0.5 c = .505 def toroParam1(u, v): return ((a + b * cos(v)) * cos(u), (a + b * cos(v)) * sin(u), b * sin(v)) def toroParam2(u, v): return ((a + c * cos(v)) * cos(u), (a + c * cos(v)) * sin(u), c * sin(v)) def curvaPlana(t): return (t, t) def curvaToro(t): return toroParam2(*curvaPlana(t)) toro = ParametricPlot3D(toroParam1, (0, 2 * pi, 150), (0, 2 * pi, 100)) toro.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) toro.setTransparency(.4) curva = Curve3D(curvaToro, (tmin, tmax, npuntos), color=_1(146, 33, 86), width=3, nvertices=1) def recalculaCurva(**kargs): """a: vueltas horizontales, b: vueltas verticales""" keys = kargs.keys() if "a" in keys: recalculaCurva.a = kargs["a"] if "b" in keys: recalculaCurva.b = kargs["b"] def curvaPlana(t): return (recalculaCurva.a * t, recalculaCurva.b * t) def curvaToro(t): return toroParam2(*curvaPlana(t)) curva.updatePoints(curvaToro) recalculaCurva.a = 1 recalculaCurva.b = 1 sp1 = SpinBox("a", (0, 20, 1), lambda x: recalculaCurva(a=x), parent=self) sp2 = SpinBox("b", (0, 20, 1), lambda x: recalculaCurva(b=x), parent=self) self.addChild(curva) self.addChild(toro) curva.animation.setDuration(5000) self.setupAnimations([curva])
def __init__(self): Page.__init__(self, u"Campo 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)
import sys from math import exp, sin, cosh, tanh, cos, tan, pi from PyQt4 import QtGui from superficie.nodes import Curve3D from superficie.viewer import MinimalViewer app = QtGui.QApplication(sys.argv) viewer = MinimalViewer() r = 3 m = tan(pi / 60) t0 = pi / 2 def sigmoid(t): return abs(2.0/(1+exp(-(t/15.0)))-1) def loxodrome(t): t = t * sigmoid(t) return r * cos(-t) / cosh(m * (-t - t0)), r * sin(-t) / cosh(m * (-t - t0)), r * tanh(m * (-t - t0)) # max_distance and max_angle are hints for the refinement algorithm (optionals) curve = Curve3D(loxodrome, (-75, 60, 10), width=1, max_distance=.3, max_angle=.2) viewer.addChild(curve).viewAll().resize(400, 400) viewer.show() sys.exit(app.exec_())
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) ])
def creaLoxodroma(self): tmin = -75 tmax = 60 pmin = 0 pmax = 2 * pi r = 3 r2 = r - 0.005 m = tan(pi / 60) t0 = pi / 2 def sigmoide(t): return abs(2.0 / (1 + exp(-(t / 15.0))) - 1) def func(t): t = t * sigmoide(t) return r * cos(-t) / cosh(m * (-t - t0)), r * sin(-t) / cosh( m * (-t - t0)), r * tanh(m * (-t - t0)) def cp(t): t = t * sigmoide(t) den1 = cosh(m * (-t - t0)) return Vec3( -r * sin(t) / den1 + r * cos(t) * sinh(m * (-t - t0)) * m / den1**2, -r * cos(t) / den1 - r * sin(t) * sinh(m * (-t - t0)) * m / den1**2, -r * (1 - tanh(m * (-t - t0))**2) * m) curve = Curve3D(func, (tmin, tmax, 10), color=(1, 1, 0), width=3, nvertices=1, max_distance=.3, max_angle=.2) self.addChild(curve) tangent = curve.attachField( "tangente", cp).setLengthFactor(1).setWidthFactor(.2).show() tangent.setRadius(.04) tangent.animation.setDuration(30000) matHead = SoMaterial() matHead.ambientColor = (.33, .22, .27) matHead.diffuseColor = (1, 0, 0) matHead.specularColor = (.99, .94, .81) matHead.shininess = .28 self.setupAnimations( [AnimationGroup([curve, tangent], (20000, 0, len(curve) - 1))]) resf = 2.97 esf = ParametricPlot3D( lambda t, f: (resf * sin(t) * cos(f), resf * sin(t) * sin(f), resf * cos(t)), (0, pi, 100), (0, 2 * pi, 120)) esf.setTransparencyType( SoTransparencyType.SORTED_OBJECT_SORTED_TRIANGLE_BLEND) esf.setTransparency(0.4) esf.setDiffuseColor(_1(28, 119, 68)) self.addChild(esf) VisibleCheckBox("esfera", esf, True, parent=self) ## los meridianos sep = SoSeparator() mer = Curve3D(lambda t: (0, r2 * cos(t), r2 * sin(t)), (pmin, pmax, 100), color=_1(72, 131, 14)) for i in range(24): sep.addChild(rot(2 * pi / 24)) sep.addChild(mer.root) # highlighted meridians r3 = r + 0.005 mer2 = Curve3D(lambda t: (0, r3 * cos(t), r3 * sin(t)), (pmin, pmax, 100), color=_1(255, 251, 0), width=2) for i in [-4, -2]: sep.addChild(rot(i * 2 * pi / 24)) sep.addChild(mer2.root) self.addChild(sep)