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) curves = [] curves.append( curva ) # Super hack muy malo!!! ncurves = 17 for i in range(1,ncurves): curves.append( Curve3D(curvaToro, (tmin, tmax, npuntos), color=_1((146-i*84)%240, (32+i*128)%250, (86+i*62)%220), width=3, nvertices=1) ) curves[i].hide() 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.atrans, recalculaCurva.b * t + recalculaCurva.btrans ) def curvaToro(t): return toroParam2(*curvaPlana(t)) recalculaCurva.atrans = 0 recalculaCurva.btrans = 0 curva.updatePoints(curvaToro) for i in range(1,ncurves): curves[i].hide() n = gcd( recalculaCurva.a, recalculaCurva.b ) if n > 1 and recalculaCurva.a != 0 and recalculaCurva.b != 0: self.chbox.setText( u"Ocultar curvas adicionales." + u"\nNúmero total de curvas disjuntas: " + str(n) ) self.chbox.setEnabled(True) #print n for i in range(1,n): #if recalculaCurva.a >= recalculaCurva.b: recalculaCurva.atrans = i*2*pi/recalculaCurva.b #else: #recalculaCurva.btrans = i*2*pi/recalculaCurva.b curves[i].updatePoints(curvaToro) if not self.chbox.isChecked(): curves[i].show() else: self.chbox.setText("Ocultar curvas adicionales") self.chbox.setEnabled(False) 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) def showExtraCurves(): #recalculaCurva(recalculaCurva.a,recalculaCurva.b) n = gcd( recalculaCurva.a, recalculaCurva.b ) if n > 1 and recalculaCurva.a != 0 and recalculaCurva.b != 0: for i in range(1,n): curves[i].show() def hideExtraCurves(): for i in range(1,ncurves): curves[i].hide() self.chbox = CheckBox( hideExtraCurves, showExtraCurves, "Ocultar curvas adicionales", state=False ) self.chbox.setEnabled(False) self.addWidget( self.chbox ) self.addChild(toro) #self.addChild(curva) self.addChildren( curves ) curva.animation.setDuration(5000) #self.setupAnimations([curva]) self.setupAnimations( curves ) #recalculaCurva(1,1) curva.updatePoints(curvaToro)
def __init__(self, text, ob, state=True, parent=None): CheckBox.__init__(self, ob.show, ob.hide, text, state) if parent: parent.addWidget(self)
class Toro(Page): u""" <p> En un <b>toro</b> hueco hay curvas que rodean tanto al hoyo central <b>(a)</b> como al hueco <b>(b)</b>. Las mostradas en la interacción se cierran sin cortarse aunque den varias vueltas en torno al hueco, al hoyo central o ambos. <p> Hay otras curvas que se enredan infinitamente en el toro sin cortarse y constituyen un <b>conjunto denso</b> en el toro.” <p> Con la parametrización del toro<br> <b>((r cos u + R) cos v, (r cos u + R) sen v, r sen v)</b>,<br> los puntos de las curvas tóricas mostradas en la interacción satisfacen <b>v = mu</b>, donde <b>m = b/a</b> es un número racional. """ 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) curves = [] curves.append( curva ) # Super hack muy malo!!! ncurves = 17 for i in range(1,ncurves): curves.append( Curve3D(curvaToro, (tmin, tmax, npuntos), color=_1((146-i*84)%240, (32+i*128)%250, (86+i*62)%220), width=3, nvertices=1) ) curves[i].hide() 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.atrans, recalculaCurva.b * t + recalculaCurva.btrans ) def curvaToro(t): return toroParam2(*curvaPlana(t)) recalculaCurva.atrans = 0 recalculaCurva.btrans = 0 curva.updatePoints(curvaToro) for i in range(1,ncurves): curves[i].hide() n = gcd( recalculaCurva.a, recalculaCurva.b ) if n > 1 and recalculaCurva.a != 0 and recalculaCurva.b != 0: self.chbox.setText( u"Ocultar curvas adicionales." + u"\nNúmero total de curvas disjuntas: " + str(n) ) self.chbox.setEnabled(True) #print n for i in range(1,n): #if recalculaCurva.a >= recalculaCurva.b: recalculaCurva.atrans = i*2*pi/recalculaCurva.b #else: #recalculaCurva.btrans = i*2*pi/recalculaCurva.b curves[i].updatePoints(curvaToro) if not self.chbox.isChecked(): curves[i].show() else: self.chbox.setText("Ocultar curvas adicionales") self.chbox.setEnabled(False) 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) def showExtraCurves(): #recalculaCurva(recalculaCurva.a,recalculaCurva.b) n = gcd( recalculaCurva.a, recalculaCurva.b ) if n > 1 and recalculaCurva.a != 0 and recalculaCurva.b != 0: for i in range(1,n): curves[i].show() def hideExtraCurves(): for i in range(1,ncurves): curves[i].hide() self.chbox = CheckBox( hideExtraCurves, showExtraCurves, "Ocultar curvas adicionales", state=False ) self.chbox.setEnabled(False) self.addWidget( self.chbox ) self.addChild(toro) #self.addChild(curva) self.addChildren( curves ) curva.animation.setDuration(5000) #self.setupAnimations([curva]) self.setupAnimations( curves ) #recalculaCurva(1,1) curva.updatePoints(curvaToro)
def __init__(self, text,ob, state=True, parent = None): CheckBox.__init__(self,ob.show,ob.hide,text,state) if parent: parent.addWidget(self)