# Changeset 7903:439e75ca1c61

Ignore:
Timestamp:
01/01/08 02:24:35 (5 years ago)
Branch:
default
Message:

3d plotting -- more work on parametric plotting.

Location:
sage
Files:
4 edited

Unmodified
Removed
• ## sage/plot/plot3d/parametric_plot3d.py

 r7902 We demonstrate each of the four ways to call this function. 1. A space curve defined by three functions of 1 variable: sage: show(parametric_plot3d( (sin, cos, lambda u: u/10), (0, 20))) Note above the lambda function, which creates a callable Python function that sends u to u/10. 2. Next we draw the same plot as above, but using symbolic functions: sage: var('u') sage: show(parametric_plot3d( (sin(u), cos(u), u/10), (u, 0, 20))) 3. We draw a parametric surface using 3 Python functions (defined using lambda): 1. A space curve defined by three functions of 1 variable: sage: show(parametric_plot3d( (sin, cos, lambda u: u/10), (0, 20))) Note above the lambda function, which creates a callable Python function that sends u to u/10. 2. Next we draw the same plot as above, but using symbolic functions: sage: var('u') sage: show(parametric_plot3d( (sin(u), cos(u), u/10), (u, 0, 20))) 3. We draw a parametric surface using 3 Python functions (defined using lambda): sage: f = (lambda u,v: cos(u), lambda u,v: sin(u)+cos(v), lambda u,v: sin(v)) sage: show(parametric_plot3d(f, (0, 2*pi), (-pi, pi))) 4. The same surface, but where the defining functions are symbolic: sage: var('u,v') sage: show(parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi))) We call the space curve function but with polynomials instead of symbolic variables. sage: R. = RDF[] sage: show(parametric_plot3d( (t, t^2, t^3), (t, 0, 3) ) ) 4. The same surface, but where the defining functions are symbolic: sage: var('u,v') sage: show(parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi))) Next we plot the same curve, but because we use (0, 3) instead of (t, 0, 3), each polynomial is viewed as a callable function of one variable: sage: show(parametric_plot3d( (t, t^2, t^3), (0, 3) ) ) We do a plot but mix a symbolic input, and an integer: sage: var('t') sage: show(parametric_plot3d( (1, sin(t), cos(t)), (t, 0, 3) ) ) We plot two interlinked tori: sage: f1 = (4+(3+cos(v))*sin(u), 4+(3+cos(v))*cos(u), 4+sin(v)) sage: f2 = (8+(3+cos(v))*cos(u), 3+sin(v), 4+(3+cos(v))*sin(u)) sage: p1 = parametric_plot3d(f1, (u,0,2*pi), (v,0,2*pi), texture="red") sage: p2 = parametric_plot3d(f2, (u,0,2*pi), (v,0,2*pi), texture="blue") sage: show(p1 + p2) """ # TODO: fail = 0 f_x, f_y, f_z = f if u is None: f_x, f_y, f_z = f for t in vals: try: fail += 1 else: f_x, f_y, f_z = [ensure_subs(m) for m in f] for t in vals: try: w.append((float(f_x.substitute({u:t})), float(f_y.substitute({u:t})), float(f_z.substitute({u:t})))) w.append((float(f_x.subs({u:t})), float(f_y.subs({u:t})), float(f_z.subs({u:t})))) except TypeError: fail += 1 if fail > 0: print "WARNING: Failed to evaluate parametric plot at %s points"%fail if v is None: raise ValueError, "both ranges must specify a variable or neither must" f0, f1, f2 = f f0, f1, f2 = [ensure_subs(w) for w in f] def f_x(uu,vv): return float(f0.substitute({u:uu, v:vv})) return float(f0.subs({u:uu, v:vv})) def f_y(uu,vv): return float(f1.substitute({u:uu, v:vv})) return float(f1.subs({u:uu, v:vv})) def f_z(uu,vv): return float(f2.substitute({u:uu, v:vv})) return float(f2.subs({u:uu, v:vv})) def g(x,y): v.append(b) return v def ensure_subs(f): if not hasattr(f, 'subs'): from sage.calculus.all import SR return SR(f) return f
• ## sage/rings/polynomial/polynomial_element.pyx

 r7618 sage: f.subs(5) 127 """ sage: f.subs({x:2}) 7 sage: f.subs({}) x^3 + x - 3 sage: f.subs({'x':2}) Traceback (most recent call last): ... TypeError: keys do not match self's parent """ if len(x) == 1 and isinstance(x[0], dict): g = self.parent().gen() if x[0].has_key(g): return self(x[0][g]) elif len(x[0]) > 0: raise TypeError, "keys do not match self's parent" return self return self.__call__(*x, **kwds)
• ## sage/server/notebook/cell.py

 r7902 else: size = 200 popup  = """
Enlarge 3d View"""%url popup  = """
Enlarge"""%url script = '%s' % (size, url, popup) images.append(script)
• ## sage/server/notebook/js.py

 r7902 function jmol_popup(url) { win = window.open ("", url, "width=400,height=400,resizable=1"); win = window.open ("", "jmol viewer", "width=400,height=400,resizable=1,statusbar=0"); win.document.body.innerHTML = ""; win.document.title = "Sage 3d Viewer"; win.document.writeln("

Sage 3d Viewer

"); jmolSetDocument(win.document); jmolApplet("100%", "script" + url); win.focus(); } """ window.open ("/history", "", "menubar=1,scrollbars=1,width=800,height=600, toolbar=1,resizable=1"); }
Note: See TracChangeset for help on using the changeset viewer.