def __init__(self): """F(x,y)=x^2 + y^2 - z = 0""" Page.__init__(self, u"Paraboloide Elíptico<br><br>F(x,y)=(x, y, x<sup>2</sup>/a<sup>2</sup> + y<sup>2</sup>/b<sup>2</sup>)") z = 0.5 par = RevolutionPlot3D(lambda r, t: r ** 2 + z, (0, 1.42), (0, 2 * pi)) x, y, z2, u, v, cose, sen, t = createVars(['x', 'y', 'z', 'u', 'v', 'cos', 'sen', 't']) mesh1 = Plot3D(lambda x, y, h: h * (x ** 2 + y ** 2 + z - .01), (-1, 1), (-1, 1)) #mesh1.addEqn(x**2+y**2 - z2**2 == 1) mesh1.addFunction(lambda x, y, h: h * (x ** 2 + y ** 2 + z + .01)) mesh1.setLinesVisible(True) mesh1.setMeshVisible(False) mesh1.setBoundingBox(zrange=(-1, 3.0)) par.setAmbientColor(_1(145, 61, 74)) par.setDiffuseColor(_1(145, 61, 74)) par.setSpecularColor(_1(145, 61, 74)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(par) self.addChild(mesh1) self.addChild(baseplane)
def __init__(self): u"""^2 + y^2 = z^2""" Page.__init__(self, u"Esfera, parametrización por proyecciones estereográficas") r = .998 esf = ParametricPlot3D(lambda t, f: (r * sin(t) * cos(f), r * sin(t) * sin(f), r * cos(t)), (0, pi, 70), (0, 2 * pi, 70)) # esf.setAmbientColor(_1(99,136,63)) esf.setDiffuseColor(_1(99, 136, 63)) esf.setSpecularColor(_1(99, 136, 63)) def proyZm1(u, v, t1): """proy desde el polo norte al plano z=-1""" den = u ** 2 + v ** 2 + 4 x = u - t1 * (u - 4 * u / den) y = v - t1 * (v - 4 * v / den) z = -1 - t1 * (-2 + 8 / den) return (x, y, z) def proyZ1(u, v, t2): """proy desde el polo sur al plano z=1""" den = u ** 2 + v ** 2 + 4 x = u - t2 * (u - 4 * u / den) y = v - t2 * (v - 4 * v / den) z = 1 - t2 * (2 - 8 / den) return (x, y, z) stereo = ParametricPlot3D(proyZm1, (-3, 3, 70), (-3, 3, 70)) stereo.setLinesVisible(True) stereo.setMeshVisible(False) stereo.setMeshDiffuseColor(_1(117, 55, 79)) stereo2 = ParametricPlot3D(proyZ1, (-3, 3, 70), (-3, 3, 70)) stereo2.setLinesVisible(True) stereo2.setMeshVisible(False) stereo2.setMeshDiffuseColor(_1(80, 87, 193)) stereo2.setTransparency(0.5) stereo2.setTransparencyType(8) baseplane = BasePlane() baseplane.setHeight(-1.005) baseplane.setRange((-4, 4, 7)) self.addChild(esf) self.addChild(stereo2) self.addChild(stereo) self.addChild(baseplane) params = [stereo,stereo2] ## no queremos los controles for i,p in enumerate(params): p.parameters['t%d' % (i+1)].hide() anims = [p.parameters['t%d' % (i+1)].asAnimation() for i,p in enumerate(params)] self.setupAnimations(anims)
def setupPlanes(self, r0=(-1, 1, 5)): self.coordPlanes = { 'xy': BasePlane(plane="xy").setDiffuseColor((1, 1, 0)), 'xz': BasePlane(plane="xz").setDiffuseColor((1, 0, 1)), 'yz': BasePlane(plane="yz").setDiffuseColor((0, 1, 1)) } for p in self.coordPlanes.values(): p.setRange(r0) p.setHeight(r0[0]) self.addChild(p)
def __init__(self, color, origin, p1, p2): BaseObject.__init__(self) self.range = (-1, 1, 10) self.base_plane = BasePlane() self.base_plane.setDiffuseColor(color) self.base_plane.setEmissiveColor(color) self.separator.addChild(self.base_plane.root) # local axis self.localXAxis = Line([], color=(1, 0, 0)) self.localYAxis = Line([], color=(1, 0, 0)) self.separator.addChild(self.localXAxis.root) self.separator.addChild(self.localYAxis.root) # calculate the points self.setPoints(origin, p1, p2)
def __init__(self): "x^2 + y^2 = z^2" Page.__init__(self, u"Semicono de revolución<br><br>F(θ,ρ)=(θ,ρ,π/4)") cono = RevolutionPlot3D(lambda r, t: r + 1, (0, 1), (0, 2 * pi)) cono1 = RevolutionPlot3D(lambda r, t, h: h * (r + 1), (0.05, 1), (0, 2 * pi)) #@UndefinedVariable cono1.setLinesVisible(True) cono1.setMeshVisible(False) cono.setDiffuseColor(_1(149, 24, 82)) cono.setSpecularColor(_1(149, 24, 82)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(cono) self.addChild(cono1) self.addChild(baseplane)
def __init__(self): "x^2 - y^2 - z = 0" Page.__init__(self, u"Paraboloide Hiperbólico<br><br>F(x,y)=(x, y, x<sup>2</sup>-y<sup>2</sup>)") z = 1.5 parab = Plot3D(lambda x, y: x ** 2 - y ** 2 + z, (-1, 1), (-1, 1)) parab1 = Plot3D(lambda x, y, h: h * (x ** 2 - y ** 2 + z), (-1, 1), (-1, 1)) #@UndefinedVariable parab1.setLinesVisible(True) parab1.setMeshVisible(False) parab.setAmbientColor(_1(145, 61 , 74)) parab.setDiffuseColor(_1(127, 119, 20)) parab.setSpecularColor(_1(145, 61 , 74)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(parab) self.addChild(parab1) self.addChild(baseplane)
def __init__(self): """F(x,y)=x^2 + y^2 - z = 0""" Page.__init__( self, u"Paraboloide Elíptico<br><br>F(x,y)=(x, y, x<sup>2</sup>/a<sup>2</sup> + y<sup>2</sup>/b<sup>2</sup>)" ) z = 0.5 par = RevolutionPlot3D(lambda r, t: r**2 + z, (0, 1), (0, 2 * pi)) x, y, z2, u, v, cose, sen, t = createVars( ['x', 'y', 'z', 'u', 'v', 'cos', 'sen', 't']) mesh1 = Plot3D(lambda x, y, h: h * (x**2 + y**2 + z - .01), (-1, 1), (-1, 1)) mesh1.addEqn(x**2 + y**2 - z2**2 == 1) mesh1.addFunction(lambda x, y, h: h * (x**2 + y**2 + z + .01)) mesh1.setLinesVisible(True) mesh1.setMeshVisible(False) mesh1.setBoundingBox(zrange=(-1, 1.5)) par.setAmbientColor(_1(145, 61, 74)) par.setDiffuseColor(_1(145, 61, 74)) par.setSpecularColor(_1(145, 61, 74)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(par) self.addChild(mesh1) self.addChild(baseplane)
class Plane(BaseObject): """A plane that contains the points: origin, p1, p2 """ def __init__(self, color, origin, p1, p2): BaseObject.__init__(self) self.range = (-1, 1, 10) self.base_plane = BasePlane() self.base_plane.setDiffuseColor(color) self.base_plane.setEmissiveColor(color) self.separator.addChild(self.base_plane.root) # local axis self.localXAxis = Line([], color=(1, 0, 0)) self.localYAxis = Line([], color=(1, 0, 0)) self.separator.addChild(self.localXAxis.root) self.separator.addChild(self.localYAxis.root) # calculate the points self.setPoints(origin, p1, p2) def setPoints(self, origin, vector1, vector2): v1 = (vector1 - origin) v2 = (vector2 - origin) ## the plane generated by {v1, v2} def plane(h, t): return Vec3(origin) + h * v1 + t * v2 self.base_plane.setRange(self.range, plane=plane) ## lines along the generators t_min, t_max, n = self.range self.localXAxis.setPoints( [plane(*pt) for pt in [(t_min, 0), (t_max, 0)]]) self.localYAxis.setPoints( [plane(*pt) for pt in [(0, t_min), (0, t_max)]])
class Plane(BaseObject): """A plane that contains the points: origin, p1, p2 """ def __init__(self, color, origin, p1, p2): BaseObject.__init__(self) self.range = (-1, 1, 10) self.base_plane = BasePlane() self.base_plane.setDiffuseColor(color) self.base_plane.setEmissiveColor(color) self.separator.addChild(self.base_plane.root) # local axis self.localXAxis = Line([], color=(1, 0, 0)) self.localYAxis = Line([], color=(1, 0, 0)) self.separator.addChild(self.localXAxis.root) self.separator.addChild(self.localYAxis.root) # calculate the points self.setPoints(origin, p1, p2) def setPoints(self, origin, vector1, vector2): v1 = (vector1 - origin) v2 = (vector2 - origin) ## the plane generated by {v1, v2} def plane(h, t): return Vec3(origin) + h * v1 + t * v2 self.base_plane.setRange(self.range, plane=plane) ## lines along the generators t_min, t_max, n = self.range self.localXAxis.setPoints([plane(*pt) for pt in [(t_min, 0), (t_max, 0)]]) self.localYAxis.setPoints([plane(*pt) for pt in [(0, t_min), (0, t_max)]])
def __init__(self): "x^4 + 2x^2y^2 + y^4 -z = 0" Page.__init__( self, u"Superficie cuártica<br><br>F(x,y)=(x,y,x<sup>4</sup>+2x<sup>2</sup>y<sup>2</sup>+y<sup>4</sup>)" ) # cuart = Plot3D(lambda x,y: x**4 + 2*x**2*y**2 + y**4 + 1, (-1,1),(-1,1)) cuart = RevolutionPlot3D(lambda r, t: r**4 + 1, (0, 1), (0, 2 * pi)) # cuart.setScaleFactor((1,1,.6)) mesh1 = Plot3D(lambda x, y, h: h * (x**4 + 2 * x**2 * y**2 + y**4 + 1), (-1, 1), (-1, 1)) mesh1.setLinesVisible(True) mesh1.setMeshVisible(False) mesh1.setBoundingBox(zrange=(-1, 2)) # cuart.setAmbientColor(_1(168,211,8)) cuart.setDiffuseColor(_1(168, 211, 8)) cuart.setSpecularColor(_1(168, 211, 8)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(cuart) self.addChild(mesh1) self.addChild(baseplane)
def __init__(self): "x^3 - 3xy^2 - z = 0" Page.__init__(self, u"Silla del mono<br><br>F(x,y)=(x, y, x<sup>3</sup> - 3xy<sup>2</sup>)") silla = Plot3D(lambda x, y: x ** 3 - 3 * x * y ** 2 + 2.5, (-1, 1), (-1, 1)) silla.setAmbientColor(_1(151, 139, 125)) silla.setDiffuseColor(_1(151, 139, 125)) silla.setSpecularColor(_1(151, 139, 125)) # silla.setShininess(1) # plano.setScaleFactor((1,1,.6)) def cVec(pto): "pto: Vec3" return pto * 1.1 silla.addVectorField(cVec) # def setXscale(t): # scale.scaleFactor = (1,1,t) # Slider( # rangep=('z', .2, 1, 1, 20), # func=setXscale, # parent=self # ) # silla1 = Plot3D(lambda x, y, h: h * (x ** 3 - 3 * x * y ** 2 + 2.5), (-1, 1), (-1, 1)) #@UndefinedVariable # silla1.setScaleFactor((1,1,.6)) silla1.setLinesVisible(True) silla1.setMeshVisible(False) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(silla) self.addChild(silla1) self.addChild(baseplane)
def __init__(self): #u"""x^2 + y^2 + z^2 = 1""" super(EsferaCasquetes,self).__init__(u"Otro atlas de la esfera") r = .98 esf = ParametricPlot3D(lambda t, f: (r * sin(t) * cos(f), r * sin(t) * sin(f), r * cos(t)), (0, pi, 70), (0, 2 * pi, 70)) esf.setDiffuseColor(_1(99, 136, 63)) esf.setSpecularColor(_1(99, 136, 63)) pars = [ lambda u,v, t1: (u, v, 1.5-t1*(1.5-sqrt(1 - u**2 - v**2))), lambda u,v, t2: (u, v, -1.5-t2*(-1.5+sqrt(1 - u**2 - v**2))), lambda u,v, t3: (u, 1.5-t3*(1.5-sqrt(1 - u**2 - v**2)),v), lambda u,v, t4: (u, -1.5-t4*(-1.5+sqrt(1 - u**2 - v**2)),v), lambda u,v, t5: (1.5-t5*(1.5-sqrt(1 - u**2 - v**2)),u,v), lambda u,v, t6, : (-1.5-t6*(-1.5+sqrt(1 - u**2 - v**2)),u,v) ] d = 0.707106 colores = [(0,0,1),(0,0,1),(0,1,0),(0,1,0),(1,0,0),(1,0,0)] planos = [ParametricPlot3D(par, (-d, d, 40), (-d, d, 40)).setLinesVisible(True).setMeshVisible(False).setMeshDiffuseColor(colores[i]) for i,par in enumerate(pars)] baseplane = BasePlane() baseplane.setHeight(-1.005) baseplane.setRange((-2,2, 7)) self.addChild(esf) for p in planos: self.addChild(p) self.addChild(baseplane) ## no queremos los controles for i,plano in enumerate(planos): plano.parameters['t%d' % (i+1)].hide() anims = [plano.parameters['t%d' % (i+1)].asAnimation() for i,plano in enumerate(planos)] self.setupAnimations(anims)
def __init__(self): "x^4 + 2x^2y^2 + y^4 -z = 0" Page.__init__(self, u"Superficie cuártica<br><br>F(x,y)=(x,y,x<sup>4</sup>+2x<sup>2</sup>y<sup>2</sup>+y<sup>4</sup>)") # cuart = Plot3D(lambda x,y: x**4 + 2*x**2*y**2 + y**4 + 1, (-1,1),(-1,1)) cuart = RevolutionPlot3D(lambda r, t: r ** 4 + 1, (0, 1.4), (0, 2 * pi)) # cuart.setScaleFactor((1,1,.6)) mesh1 = Plot3D(lambda x, y, h: h * (x ** 4 + 2 * x ** 2 * y ** 2 + y ** 4 + 0.9), (-1, 1), (-1, 1)) mesh1.setLinesVisible(True) mesh1.setMeshVisible(False) mesh1.setBoundingBox(zrange=(-1, 6)) # cuart.setAmbientColor(_1(168,211,8)) cuart.setDiffuseColor(_1(168, 211, 8)) cuart.setSpecularColor(_1(168, 211, 8)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(cuart) self.addChild(mesh1) self.addChild(baseplane)
def __init__(self): #u"""x^2 + y^2 + z^2 = 1""" super(EsferaCasquetes, self).__init__(u"Otro atlas de la esfera") r = .998 esf = ParametricPlot3D( lambda t, f: (r * sin(t) * cos(f), r * sin(t) * sin(f), r * cos(t)), (0, pi, 70), (0, 2 * pi, 70)) esf.setDiffuseColor(_1(99, 136, 63)) esf.setSpecularColor(_1(99, 136, 63)) pars = [ lambda u, v, t1: (u, v, 1.5 - t1 * (1.5 - sqrt(1 - u**2 - v**2))), lambda u, v, t2: (u, v, -1 - t2 * (-1 + sqrt(1 - u**2 - v**2))), lambda u, v, t3: (u, 1.5 - t3 * (1.5 - sqrt(1 - u**2 - v**2)), v), lambda u, v, t4: (u, -1.5 - t4 * (-1.5 + sqrt(1 - u**2 - v**2)), v), lambda u, v, t5: (1.5 - t5 * (1.5 - sqrt(1 - u**2 - v**2)), u, v), lambda u, v, t6, : (-1.5 - t6 * (-1.5 + sqrt(1 - u**2 - v**2)), u, v) ] d = .7 colores = [(0, 0, 1), (0, 0, 1), (0, 1, 0), (0, 1, 0), (1, 0, 0), (1, 0, 0)] planos = [ ParametricPlot3D(par, (-d, d, 40), (-d, d, 40)).setLinesVisible( True).setMeshVisible(False).setMeshDiffuseColor(colores[i]) for i, par in enumerate(pars) ] baseplane = BasePlane() baseplane.setHeight(-1.005) baseplane.setRange((-2, 2, 7)) self.addChild(esf) for p in planos: self.addChild(p) self.addChild(baseplane) ## no queremos los controles for i, plano in enumerate(planos): plano.parameters['t%d' % (i + 1)].hide() anims = [ plano.parameters['t%d' % (i + 1)].asAnimation() for i, plano in enumerate(planos) ] self.setupAnimations(anims)
def __init__(self): "x^3 - 3xy^2 - z = 0" Page.__init__( self, u"Silla del mono<br><br>F(x,y)=(x, y, x<sup>3</sup> - 3xy<sup>2</sup>)" ) silla = Plot3D(lambda x, y: x**3 - 3 * x * y**2 + 2.5, (-1, 1), (-1, 1)) silla.setAmbientColor(_1(151, 139, 125)) silla.setDiffuseColor(_1(151, 139, 125)) silla.setSpecularColor(_1(151, 139, 125)) # silla.setShininess(1) # plano.setScaleFactor((1,1,.6)) def cVec(pto): "pto: Vec3" return pto * 1.1 silla.addVectorField(cVec) # def setXscale(t): # scale.scaleFactor = (1,1,t) # Slider( # rangep=('z', .2, 1, 1, 20), # func=setXscale, # parent=self # ) # silla1 = Plot3D(lambda x, y, h: h * (x**3 - 3 * x * y**2 + 2.5), (-1, 1), (-1, 1)) #@UndefinedVariable # silla1.setScaleFactor((1,1,.6)) silla1.setLinesVisible(True) silla1.setMeshVisible(False) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(silla) self.addChild(silla1) self.addChild(baseplane)
def __init__(self): "x^2 + y^2 = z^2" Page.__init__( self, u"Semicono de revolución<br><br>F(θ,ρ)=(θ,ρ,π/4)" ) cono = RevolutionPlot3D(lambda r, t: r + 1, (0, 1), (0, 2 * pi)) cono1 = RevolutionPlot3D(lambda r, t, h: h * (r + 1), (0.05, 1), (0, 2 * pi)) #@UndefinedVariable cono1.setLinesVisible(True) cono1.setMeshVisible(False) cono.setDiffuseColor(_1(149, 24, 82)) cono.setSpecularColor(_1(149, 24, 82)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(cono) self.addChild(cono1) self.addChild(baseplane)
def __init__(self): "x^2 - y^2 - z = 0" Page.__init__( self, u"Paraboloide Hiperbólico<br><br>F(x,y)=(x, y, x<sup>2</sup>-y<sup>2</sup>)" ) z = 1.5 parab = Plot3D(lambda x, y: x**2 - y**2 + z, (-1, 1), (-1, 1)) parab1 = Plot3D(lambda x, y, h: h * (x**2 - y**2 + z), (-1, 1), (-1, 1)) #@UndefinedVariable parab1.setLinesVisible(True) parab1.setMeshVisible(False) parab.setAmbientColor(_1(145, 61, 74)) parab.setDiffuseColor(_1(127, 119, 20)) parab.setSpecularColor(_1(145, 61, 74)) baseplane = BasePlane() baseplane.setHeight(0) baseplane.setRange((-2, 2, 7)) self.addChild(parab) self.addChild(parab1) self.addChild(baseplane)
def __init__(self): """x^2 - y^2 - z = 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])
def __init__(self): u"""^2 + y^2 = z^2""" Page.__init__( self, u"Esfera, parametrización por proyecciones estereográficas") r = .998 esf = ParametricPlot3D( lambda t, f: (r * sin(t) * cos(f), r * sin(t) * sin(f), r * cos(t)), (0, pi, 70), (0, 2 * pi, 70)) # esf.setAmbientColor(_1(99,136,63)) esf.setDiffuseColor(_1(99, 136, 63)) esf.setSpecularColor(_1(99, 136, 63)) def proyZm1(u, v, t1): """proy desde el polo norte al plano z=-1""" den = u**2 + v**2 + 4 x = u - t1 * (u - 4 * u / den) y = v - t1 * (v - 4 * v / den) z = -1 - t1 * (-2 + 8 / den) return (x, y, z) def proyZ1(u, v, t2): """proy desde el polo sur al plano z=1""" den = u**2 + v**2 + 4 x = u - t2 * (u - 4 * u / den) y = v - t2 * (v - 4 * v / den) z = 1 - t2 * (2 - 8 / den) return (x, y, z) stereo = ParametricPlot3D(proyZm1, (-3, 3, 70), (-3, 3, 70)) stereo.setLinesVisible(True) stereo.setMeshVisible(False) stereo.setMeshDiffuseColor(_1(117, 55, 79)) stereo2 = ParametricPlot3D(proyZ1, (-3, 3, 70), (-3, 3, 70)) stereo2.setLinesVisible(True) stereo2.setMeshVisible(False) stereo2.setMeshDiffuseColor(_1(80, 87, 193)) stereo2.setTransparency(0.5) stereo2.setTransparencyType(8) baseplane = BasePlane() baseplane.setHeight(-1.005) baseplane.setRange((-4, 4, 7)) self.addChild(esf) self.addChild(stereo2) self.addChild(stereo) self.addChild(baseplane) params = [stereo, stereo2] ## no queremos los controles for i, p in enumerate(params): p.parameters['t%d' % (i + 1)].hide() anims = [ p.parameters['t%d' % (i + 1)].asAnimation() for i, p in enumerate(params) ] self.setupAnimations(anims)