# Ticket #1828: sage-trac-1828.patch

File sage-trac-1828.patch, 23.4 KB (added by was, 14 years ago)
• ## new file sage/plot/misc.py

# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1200641394 28800
# Node ID d44d853719c1af06e33806a6483903d237c2d848
# Parent  1a9c4f6fa902d441262ca7ec29dcea7f6511e64a
trac #1828 -- 3d documentation into the reference manual

diff -r 1a9c4f6fa902 -r d44d853719c1 sage/plot/misc.py
 - def ensure_subs(f): if not hasattr(f, 'subs'): from sage.calculus.all import SR return SR(f) return f
• ## sage/plot/plot3d/bugs.txt

diff -r 1a9c4f6fa902 -r d44d853719c1 sage/plot/plot3d/bugs.txt
 a We draw a spiral of spheres: sage: v = [(sin(i),cos(i),i) for i in [-4,-3.5,..4]] sage: S = sum(sphere(v[i], size=1/2, color=((i-4)/8, 1/2,(4-i)/8)) for i in range(len(v))) sage: S.show(aspect_ratio=[1,1,1]) NOTE: The sphere above have holes in them.  This is a \emph{bug} in jmol. * Only the last jmol 3d image is displayed, e..g., in one notebook cell sage: x, y = var('x,y') sage: plot3d(x^2 + y^2, (x,-2,2), (y,-2,2))
• ## sage/plot/plot3d/examples.py

diff -r 1a9c4f6fa902 -r d44d853719c1 sage/plot/plot3d/examples.py
 a """ EXAMPLES of 3d Plots: r""" Introduction. First we draw a spiral of spheres: sage: S = sum(sphere((sin(i),cos(i),i), size=0.5,color=((i-4)/8.0, 0.5,(4-i)/8.0)) for i in [-4,-3.5,..4]) sage: S.show(aspect_ratio=[1,1,1]) (not yet written) """
• ## sage/plot/plot3d/list_plot3d.py

diff -r 1a9c4f6fa902 -r d44d853719c1 sage/plot/plot3d/list_plot3d.py
 a """ 3d list plots List Plots """ from sage.matrix.all import is_Matrix, matrix
• ## sage/plot/plot3d/parametric_plot3d.py

diff -r 1a9c4f6fa902 -r d44d853719c1 sage/plot/plot3d/parametric_plot3d.py
 a """ 3d Parametric Plots Parametric Plots """ from parametric_surface import ParametricSurface from shapes2 import line3d from texture import Texture from sage.plot.misc import ensure_subs def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", **kwds): """ r""" Return a parametric three-dimensional space curve or surface. INPUTS: There are four ways to call this function: * parametric_plot3d([f_x, f_y, f_z], (u_min, u_max)): f_x, f_y, f_z are three functions and u_min and u_max \begin{itemize} \item \code{parametric_plot3d([f_x, f_y, f_z], (u_min, u_max))}:\\ $f_x, f_y, f_z$ are three functions and $u_{\min}$ and $u_{\max}$ are real numbers * parametric_plot3d([f_x, f_y, f_z], (u, u_min, u_max)) f_x, f_y, f_z can be viewed as functions of u \item \code{parametric_plot3d([f_x, f_y, f_z], (u, u_min, u_max))}:\\ $f_x, f_y, f_z$ can be viewed as functions of $u$ * parametric_plot3d([f_x, f_y, f_z], (u_min, u_max), (v_min, v_max)) f_x, f_y, f_z are each functions of two variables \item \code{parametric_plot3d([f_x, f_y, f_z], (u_min, u_max), (v_min, v_max))}:\\ $f_x, f_y, f_z$ are each functions of two variables * parametric_plot3d([f_x, f_y, f_z], (u, u_min, u_max), (v, v_min, v_max)) f_x, f_y, f_z can be viewed as functions of u and v \item \code{parametric_plot3d([f_x, f_y, f_z], (u, u_min, u_max), (v, v_min, v_max))}: \\ $f_x, f_y, f_z$ can be viewed as functions of $u$ and $v$ \end{itemize} The INPUTS are as follows: INPUT: f -- a 3-tuple of functions or expressions urange -- a 2-tuple (u_min, u_max) or a 3-tuple (u, u_min, u_max) vrange -- (optional -- only used for surfaces) a 2-tuple (u_min, u_max) def parametric_plot3d(f, urange, vrange= and a pair of integers for a surface. NOTES: * By default for a curve any points where f_x, f_y, or f_z do \begin{enumerate} \item By default for a curve any points where f_x, f_y, or f_z do not evaluate to a real number are skipped. * Currently for a surface f_x, f_y, and f_z have to be defined \item Currently for a surface f_x, f_y, and f_z have to be defined everywhere. This will change. \end{enumerate} EXAMPLES: We demonstrate each of the four ways to call this function. 1. A space curve defined by three functions of 1 variable: \begin{enumerate} \item A space curve defined by three functions of 1 variable: sage: 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: \item Next we draw the same plot as above, but using symbolic functions: sage: u = var('u') sage: parametric_plot3d( (sin(u), cos(u), u/10), (u, 0, 20)) 3. We draw a parametric surface using 3 Python functions (defined using \item 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: parametric_plot3d(f, (0, 2*pi), (-pi, pi)) 4. The same surface, but where the defining functions are symbolic: \item The same surface, but where the defining functions are symbolic: sage: u, v = var('u,v') sage: parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi)) We increase the number of plot points, and make the surface green and transparent: sage: parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi), color='green', opacity=0.1, plot_points=[30,30]) sage: parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi), color='green', opacity=0.1, plot_points=[30,30]) \end{enumerate} We call the space curve function but with polynomials instead of symbolic variables. def parametric_plot3d(f, urange, vrange= return G def parametric_plot3d_curve(f, urange, plot_points, **kwds): r""" This function is used internally by the \code{parametric_plot3d} command. """ from sage.plot.plot import var_and_list_of_values plot_points = int(plot_points) u, vals = var_and_list_of_values(urange, plot_points) def parametric_plot3d_curve(f, urange, p return line3d(w, **kwds) def parametric_plot3d_surface(f, urange, vrange, plot_points, **kwds): r""" This function is used internally by the \code{parametric_plot3d} command. """ if not isinstance(plot_points, (list, tuple)) or len(plot_points) != 2: raise ValueError, "plot_points must be a tuple of length 2" points0, points1 = plot_points def parametric_plot3d_surface(f, urange, return (float(f_x(x,y)), float(f_y(x,y)), float(f_z(x,y))) return ParametricSurface(g, (u_vals, v_vals), **kwds) def ensure_subs(f): if not hasattr(f, 'subs'): from sage.calculus.all import SR return SR(f) return f
• ## sage/plot/plot3d/platonic.py

diff -r 1a9c4f6fa902 -r d44d853719c1 sage/plot/plot3d/platonic.py
• ## sage/plot/tachyon.py

diff -r 1a9c4f6fa902 -r d44d853719c1 sage/plot/tachyon.py
 a r""" r""" 3D Plotting Using Tachyon The Tachyon 3D Ray Tracer Given any 3D graphics object one can compute a raytraced representation by typing \code{show(viewer='tachyon')}.  For example, we draw two translucent spheres that contain a red tube, and render the result using Tachyon. sage: S = sphere(opacity=0.8, aspect_ratio=[1,1,1]) sage: L = line3d([(0,0,0),(2,0,0)], thickness=10, color='red') sage: M = S + S.translate((2,0,0)) + L sage: M.show(viewer='tachyon') One can also directly control Tachyon, which gives a huge amount of flexibility.  For example, here we directly use Tachyon to draw 3 spheres on the coordinate axes.  Notice that the result is gorgeous: sage: t = Tachyon(xres=500,yres=500, camera_center=(2,0,0)) sage: t.light((4,3,2), 0.2, (1,1,1)) sage: t.texture('t2', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) sage: t.texture('t3', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,1,0)) sage: t.texture('t4', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,0,1)) sage: t.sphere((0,0.5,0), 0.2, 't2') sage: t.sphere((0.5,0,0), 0.2, 't3') sage: t.sphere((0,0,0.5), 0.2, 't4') sage: t.show() AUTHOR: -- John E. Stone (johns@megapixel.com): wrote tachyon ray tracer class Tachyon(SageObject): not oriented according to the right hand rule. EXAMPLES: Three spheres on the coordinate axes: sage: t = Tachyon(xres=500,yres=500, camera_center=(2,0,0)) sage: t.light((4,3,2), 0.2, (1,1,1)) sage: t.texture('t2', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) sage: t.texture('t3', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,1,0)) sage: t.texture('t4', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,0,1)) sage: t.sphere((0,0.5,0), 0.2, 't2') sage: t.sphere((0.5,0,0), 0.2, 't3') sage: t.sphere((0,0,0.5), 0.2, 't4') sage: t.show() Sphere's along the twisted cubic. sage: t = Tachyon(xres=512,yres=512, camera_center=(3,0.3,0)) sage: t.light((4,3,2), 0.2, (1,1,1))