Changeset 8085:36a142494ced


Ignore:
Timestamp:
01/17/08 23:29:54 (5 years ago)
Author:
William Stein <wstein@…>
Branch:
default
Message:

trac #1828 -- 3d documentation into the reference manual

Location:
sage/plot
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • sage/plot/plot3d/bugs.txt

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

    r7969 r8085  
    1 """ 
    2 EXAMPLES of 3d Plots: 
     1r""" 
     2Introduction. 
    33 
    4 First we draw a spiral of spheres: 
    5    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]) 
    6    sage: S.show(aspect_ratio=[1,1,1]) 
    7  
     4(not yet written) 
    85""" 
    96    
  • sage/plot/plot3d/list_plot3d.py

    r7962 r8085  
    11""" 
    2 3d list plots 
     2List Plots 
    33""" 
    44 
  • sage/plot/plot3d/parametric_plot3d.py

    r8035 r8085  
    11""" 
    2 3d Parametric Plots 
     2Parametric Plots 
    33""" 
    44 
     
    66from shapes2 import line3d 
    77from texture import Texture 
     8from sage.plot.misc import ensure_subs 
    89 
    910def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", **kwds): 
    10     """ 
     11    r""" 
    1112    Return a parametric three-dimensional space curve or surface. 
    1213 
    13     INPUTS: 
    1414    There are four ways to call this function: 
    15         * parametric_plot3d([f_x, f_y, f_z], (u_min, u_max)): 
    16           f_x, f_y, f_z are three functions and u_min and u_max 
     15    \begin{itemize} 
     16        \item \code{parametric_plot3d([f_x, f_y, f_z], (u_min, u_max))}:\\ 
     17          $f_x, f_y, f_z$ are three functions and $u_{\min}$ and $u_{\max}$ 
    1718          are real numbers 
    1819 
    19         * parametric_plot3d([f_x, f_y, f_z], (u, u_min, u_max)) 
    20           f_x, f_y, f_z can be viewed as functions of u 
     20        \item \code{parametric_plot3d([f_x, f_y, f_z], (u, u_min, u_max))}:\\ 
     21          $f_x, f_y, f_z$ can be viewed as functions of $u$ 
    2122         
    22         * parametric_plot3d([f_x, f_y, f_z], (u_min, u_max), (v_min, v_max)) 
    23           f_x, f_y, f_z are each functions of two variables 
    24  
    25         * parametric_plot3d([f_x, f_y, f_z], (u, u_min, u_max), (v, v_min, v_max)) 
    26           f_x, f_y, f_z can be viewed as functions of u and v 
    27  
    28     The INPUTS are as follows: 
     23        \item \code{parametric_plot3d([f_x, f_y, f_z], (u_min, u_max), (v_min, v_max))}:\\ 
     24          $f_x, f_y, f_z$ are each functions of two variables 
     25 
     26        \item \code{parametric_plot3d([f_x, f_y, f_z], (u, u_min, u_max), (v, v_min, v_max))}: \\ 
     27          $f_x, f_y, f_z$ can be viewed as functions of $u$ and $v$ 
     28    \end{itemize} 
     29 
     30    INPUT: 
    2931        f -- a 3-tuple of functions or expressions 
    3032        urange -- a 2-tuple (u_min, u_max) or a 3-tuple (u, u_min, u_max) 
     
    3739 
    3840    NOTES: 
    39       * By default for a curve any points where f_x, f_y, or f_z do 
     41    \begin{enumerate} 
     42      \item By default for a curve any points where f_x, f_y, or f_z do 
    4043        not evaluate to a real number are skipped. 
    41       * Currently for a surface f_x, f_y, and f_z have to be defined 
     44      \item Currently for a surface f_x, f_y, and f_z have to be defined 
    4245        everywhere. This will change. 
     46    \end{enumerate} 
    4347 
    4448    EXAMPLES: 
    4549    We demonstrate each of the four ways to call this function. 
    46  
    47         1. A space curve defined by three functions of 1 variable: 
     50    \begin{enumerate} 
     51        \item A space curve defined by three functions of 1 variable: 
    4852            sage: parametric_plot3d( (sin, cos, lambda u: u/10), (0, 20)) 
    4953 
     
    5155        that sends u to u/10. 
    5256 
    53         2. Next we draw the same plot as above, but using symbolic functions: 
     57        \item Next we draw the same plot as above, but using symbolic functions: 
    5458            sage: u = var('u') 
    5559            sage: parametric_plot3d( (sin(u), cos(u), u/10), (u, 0, 20)) 
    5660 
    57         3. We draw a parametric surface using 3 Python functions (defined using 
     61        \item We draw a parametric surface using 3 Python functions (defined using 
    5862           lambda): 
    5963            sage: f = (lambda u,v: cos(u), lambda u,v: sin(u)+cos(v), lambda u,v: sin(v)) 
    6064            sage: parametric_plot3d(f, (0, 2*pi), (-pi, pi)) 
    6165 
    62         4. The same surface, but where the defining functions are symbolic: 
     66        \item The same surface, but where the defining functions are symbolic: 
    6367            sage: u, v = var('u,v') 
    6468            sage: parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi)) 
    6569 
    6670        We increase the number of plot points, and make the surface green and transparent: 
    67             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])             
     71            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]) 
     72 
     73    \end{enumerate} 
    6874 
    6975    We call the space curve function but with polynomials instead of 
     
    132138     
    133139def parametric_plot3d_curve(f, urange, plot_points, **kwds): 
     140    r""" 
     141    This function is used internally by the \code{parametric_plot3d} command. 
     142    """ 
    134143    from sage.plot.plot import var_and_list_of_values 
    135144    plot_points = int(plot_points) 
     
    159168 
    160169def parametric_plot3d_surface(f, urange, vrange, plot_points, **kwds): 
     170    r""" 
     171    This function is used internally by the \code{parametric_plot3d} command. 
     172    """ 
    161173    if not isinstance(plot_points, (list, tuple)) or len(plot_points) != 2: 
    162174        raise ValueError, "plot_points must be a tuple of length 2" 
     
    188200 
    189201    return ParametricSurface(g, (u_vals, v_vals), **kwds) 
    190  
    191 def ensure_subs(f): 
    192     if not hasattr(f, 'subs'): 
    193         from sage.calculus.all import SR 
    194         return SR(f) 
    195     return f 
  • sage/plot/plot3d/platonic.py

    r8063 r8085  
    11r""" 
    2 Methods for creating the five platonic solids.  
     2Platonic Solids.  
    33 
    44EXAMPLES: 
    55The five platonic solids in a row; 
    6     sage: G = tetrahedron((0,-3.5,0), color='blue') + cube((0,-2,0),color=(.25,0,.5)) + octahedron(color='red') + dodecahedron((0,2,0), color='orange') + icosahedron(center=(0,4,0), color='yellow') 
     6    sage: G = tetrahedron((0,-3.5,0), color='blue') + cube((0,-2,0),color=(.25,0,.5)) +\ 
     7          octahedron(color='red') + dodecahedron((0,2,0), color='orange') +\ 
     8          icosahedron(center=(0,4,0), color='yellow') 
    79    sage: G.show(aspect_ratio=[1,1,1]) 
    810 
    911All the platonic solids in the same place: 
    10     sage: G = tetrahedron(color='blue',opacity=0.7) + cube(color=(.25,0,.5), opacity=0.7) + octahedron(color='red', opacity=0.7) + dodecahedron(color='orange', opacity=0.7) + icosahedron(opacity=0.7) 
     12    sage: G = tetrahedron(color='blue',opacity=0.7) + \ 
     13          cube(color=(.25,0,.5), opacity=0.7) +\ 
     14          octahedron(color='red', opacity=0.7) + \ 
     15          dodecahedron(color='orange', opacity=0.7) + icosahedron(opacity=0.7) 
    1116    sage: G.show(aspect_ratio=[1,1,1]) 
    1217 
     
    7176    A 3d tetrahedron. 
    7277 
    73     INPUTS: 
     78    INPUT: 
    7479        center -- (default: (0,0,0)) 
    7580        size -- (default: 1) 
     
    114119def cube(center=(0,0,0), size=1, color=None, frame_thickness=0, frame_color=None, **kwds): 
    115120    """ 
    116     A 3d cube centered at the origin with default side lengths 1. 
    117      
    118     INPUTS: 
     121    A 3D cube centered at the origin with default side lengths 1. 
     122     
     123    INPUT: 
    119124        center -- (default: (0,0,0)) 
    120125        size -- (default: 1) the side lengths of the cube 
    121         color -- a string that describes a color; this can also be a list of 3-tuples or 
    122                  strings length 6 or 3, in which case the faces (and oppositive faces) 
    123                  are colored. 
    124         frame_thickness -- (default: 0) if positive, then thickness of the frame 
    125         frame_color -- (default: None) if given, gives the color of the frame 
     126        color -- a string that describes a color; this can also be a 
     127                 list of 3-tuples or strings length 6 or 3, in which 
     128                 case the faces (and oppositive faces) are colored. 
     129        frame_thickness -- (default: 0) if positive, then thickness of 
     130                 the frame 
     131        frame_color -- (default: None) if given, gives the color of 
     132                 the frame 
    126133        opacity -- (default: 1) if less than 1 then is transparent 
    127134 
     
    140147 
    141148    A bunch of random cubes: 
    142         sage: sum([cube((10*random(), 10*random(), 10*random()), size=random()/3, color=(random(),random(), random())) for _ in [1..30]])     
     149        sage: v = [(random(), random(), random()) for _ in [1..30]] 
     150        sage: sum([cube((10*a,10*b,10*c), size=random()/3, color=(a,b,c)) for a,b,c in v]) 
    143151 
    144152    Non-square cubes (boxes): 
     
    147155 
    148156    And one that is colored: 
    149         sage: cube(color=['red', 'blue', 'green', 'black', 'white', 'orange'], aspect_ratio=[1,1,1]).scale([1,2,3]) 
     157        sage: cube(color=['red', 'blue', 'green', 'black', 'white', 'orange'], \ 
     158                  aspect_ratio=[1,1,1]).scale([1,2,3]) 
    150159 
    151160    A nice translucent color cube with a frame: 
    152         sage: c = cube(color=['red', 'blue', 'green'], frame=False, frame_thickness=2, frame_color='brown', opacity=0.8) 
     161        sage: c = cube(color=['red', 'blue', 'green'], frame=False, frame_thickness=2, \ 
     162                       frame_color='brown', opacity=0.8) 
    153163        sage: c 
    154164         
     
    173183 
    174184def octahedron(center=(0,0,0), size=1, **kwds): 
    175     """ 
     185    r""" 
    176186    Return an octahedron. 
    177187 
    178     INPUTS: 
     188    INPUT: 
    179189        center -- (default: (0,0,0)) 
    180190        size -- (default: 1)  
    181         color -- a string that describes a color; this can also be a list of 3-tuples or 
    182                  strings length 6 or 3, in which case the faces (and oppositive faces) 
    183                  are colored. 
    184         opacity -- (default: 1) if less than 1 then is transparent 
    185  
    186     EXAMPLES: 
    187         sage: octahedron((1,4,3), color='orange') + octahedron((0,2,1), size=2, opacity=0.6)     
     191        color -- a string that describes a color; this can also be a 
     192                 list of 3-tuples or strings length 6 or 3, in which 
     193                 case the faces (and oppositive faces) are colored. 
     194        opacity -- (default: 1) if less than 1 then is transparent 
     195 
     196    EXAMPLES: 
     197        sage: octahedron((1,4,3), color='orange') + \ 
     198                     octahedron((0,2,1), size=2, opacity=0.6)     
    188199    """ 
    189200    return prep(Box(1,1,1).dual(**kwds), center, size, kwds) 
    190201 
    191202def dodecahedron(center=(0,0,0), size=1, **kwds): 
    192     """ 
     203    r""" 
    193204    A dodecahedron. 
    194205 
    195     INPUTS: 
     206    INPUT: 
    196207        center -- (default: (0,0,0)) 
    197208        size -- (default: 1)  
    198         color -- a string that describes a color; this can also be a list of 3-tuples or 
    199                  strings length 6 or 3, in which case the faces (and oppositive faces) 
    200                  are colored. 
     209        color -- a string that describes a color; this can also be a 
     210                 list of 3-tuples or strings length 6 or 3, in which 
     211                 case the faces (and oppositive faces) are colored. 
    201212        opacity -- (default: 1) if less than 1 then is transparent 
    202213 
     
    206217 
    207218    A translucent dodecahedron that contains a black sphere: 
    208         sage: dodecahedron(color='orange', opacity=0.8) + sphere(size=0.5, color='black') 
     219        sage: dodecahedron(color='orange', opacity=0.8) + \ 
     220              sphere(size=0.5, color='black') 
    209221 
    210222    CONSTRUCTION: 
     
    223235        $P_3 = \left(-\frac{1}{2}t, \frac{\sqrt{3}}{2}t, \sqrt{1-t^2}\right)$ 
    224236         
    225         $Solving $\frac{(P_1-Q) \cdot (P_2-Q)}{|P_1-Q||P_2-Q|} = \cos(3\pi/5)$ we get $t = 2/3$. 
     237 
     238        Solving $\frac{(P_1-Q) \cdot (P_2-Q)}{|P_1-Q||P_2-Q|} = 
     239        \cos(3\pi/5)$ we get $t = 2/3$. 
    226240         
    227241        Now we have 6 points $R_1, ..., R_6$ to close the three top pentagons.  
     
    279293         
    280294def icosahedron(center=(0,0,0), size=1, **kwds): 
    281     """ 
     295    r""" 
    282296    An icosahedron. 
    283297 
    284     INPUTS: 
     298    INPUT: 
    285299        center -- (default: (0,0,0)) 
    286300        size -- (default: 1)  
    287         color -- a string that describes a color; this can also be a list of 3-tuples or 
    288                  strings length 6 or 3, in which case the faces (and oppositive faces) 
    289                  are colored. 
     301        color -- a string that describes a color; this can also be a 
     302                 list of 3-tuples or strings length 6 or 3, in which 
     303                 case the faces (and oppositive faces) are colored. 
    290304        opacity -- (default: 1) if less than 1 then is transparent 
    291305 
     
    294308 
    295309    Two icosahedrons at different positions of different sizes. 
    296         sage: icosahedron((-1/2,0,1), color='orange') + icosahedron((2,0,1), size=1/2, aspect_ratio=[1,1,1]) 
     310        sage: icosahedron((-1/2,0,1), color='orange') + \ 
     311              icosahedron((2,0,1), size=1/2, aspect_ratio=[1,1,1]) 
    297312    """ 
    298313    return prep(dodecahedron().dual(**kwds), center, size, kwds) 
  • sage/plot/plot3d/plot3d.py

    r8064 r8085  
    11r""" 
    2 Functions for 3d plotting with the new graphics model. 
     2Plotting Functions. 
    33 
    44EXAMPLES:  
     
    3636    -- Robert Bradshaw 2007-08: initial version of this file 
    3737    -- William Stein 2007-12, 2008-01: improving 3d plotting 
    38      
    39 TODO: 
    40     -- smooth triangles 
    4138""" 
     39 
     40     
     41#TODO: 
     42#    -- smooth triangles 
    4243 
    4344#***************************************************************************** 
     
    110111    Adaptive 3d plotting of a function of two variables. 
    111112 
    112     INPUTS: 
     113    INPUT: 
    113114        f -- a symbolic function or a Python function of 3 variables. 
    114115        x_range -- x range of values: 2-tuple (xmin, xmax) or 3-tuple (x,xmin,xmax) 
  • sage/plot/plot3d/shapes2.py

    r7976 r8085  
     1""" 
     2Lines, Frames, Spheres, Points, Dots, and Text 
     3""" 
     4 
    15import math 
    26import shapes 
     
    1519 
    1620def line3d(points, thickness=1, radius=None, arrow_head=False, **kwds): 
    17     """ 
     21    r""" 
    1822    Draw a 3d line joining a sequence of points. 
    1923 
     
    4044 
    4145    A transparent thick green line and a little blue line: 
    42         sage: line3d([(0,0,0), (1,1,1), (1,0,2)], opacity=0.5, radius=0.1, color='green') + line3d([(0,1,0), (1,0,2)])     
     46        sage: line3d([(0,0,0), (1,1,1), (1,0,2)], opacity=0.5, radius=0.1, \ 
     47                     color='green') + line3d([(0,1,0), (1,0,2)])     
    4348    """ 
    4449    if len(points) < 2: 
     
    205210 
    206211def sphere(center=(0,0,0), size=1, **kwds): 
    207     """ 
     212    r""" 
    208213    Return a plot of a sphere of radius size centered at $(x,y,z)$. 
    209214 
     
    217222 
    218223    Two sphere's touching: 
    219        sphere(center=(-1,0,0)) + sphere(center=(1,0,0), aspect_ratio=[1,1,1]) 
     224       sage: sphere(center=(-1,0,0)) + sphere(center=(1,0,0), aspect_ratio=[1,1,1]) 
    220225 
    221226    Spheres of radii 1 and 2 one stuck into the other: 
    222        sage: sphere(color='orange') + sphere(color=(0,0,0.3),center=(0,0,-2),size=2,opacity=0.9)     
     227       sage: sphere(color='orange') + sphere(color=(0,0,0.3), \ 
     228                    center=(0,0,-2),size=2,opacity=0.9)     
    223229     
    224230    We draw a transparent sphere on a saddle.  
     
    233239     
    234240def text3d(txt, (x,y,z), **kwds): 
    235     """ 
     241    r""" 
    236242    Display 3d text. 
    237243 
     
    250256 
    251257    We draw a multicolore spiral of numbers: 
    252         sage: sum([text('%.1f'%n, (cos(n),sin(n),n), color=(n/2,1-n/2,0)) for n in [0,0.2,..,8]]) 
     258        sage: sum([text('%.1f'%n, (cos(n),sin(n),n), color=(n/2,1-n/2,0)) \ 
     259                    for n in [0,0.2,..,8]]) 
    253260    """ 
    254261    if not kwds.has_key('color') and not kwds.has_key('rgbcolor'): 
     
    304311 
    305312class Line(PrimitiveObject): 
    306     """ 
     313    r""" 
    307314    Draw a 3d line joining a sequence of points.  
    308315     
    309316    This line has a fixed diameter unaffected by transformations and zooming.  
    310     It may be smoothed if corner_cutoff < 1.  
     317    It may be smoothed if \code{corner_cutoff < 1}.  
    311318     
    312319    INPUT: 
    313320        points        -- list of points to pass through 
    314321        thickness     -- diameter of the line 
    315         corner_cutoff -- threshold for smoothing (see the corners() method) 
    316                          this is the minimum cosine between adjacent segments to smooth 
     322        corner_cutoff -- threshold for smoothing (see the corners() 
     323                         method) this is the minimum cosine between 
     324                         adjacent segments to smooth 
    317325        arrow_head    -- if True make this curve into an arrow 
    318326     
    319327    EXAMPLES:  
    320328        sage: from sage.plot.plot3d.shapes2 import Line 
    321         sage: Line([(i*math.sin(i), i*math.cos(i), i/3) for i in range(30)], arrow_head=True) 
    322          
    323         Smooth angles less than 90 degrees: 
     329        sage: Line([(i*math.sin(i), i*math.cos(i), i/3) for i in range(30)], \ 
     330                   arrow_head=True) 
     331 
     332    Smooth angles less than 90 degrees: 
    324333        sage: Line([(0,0,0),(1,0,0),(2,1,0),(0,1,0)], corner_cutoff=0) 
    325334    """ 
     
    454463    Plot a point or list of points in 3d space. 
    455464 
    456     INPUTS: 
     465    INPUT: 
    457466        v -- a point or list of points 
    458467        size -- (default: 1) size of the point (or points) 
  • sage/plot/tachyon.py

    r7541 r8085  
    11r""" 
    2 3D Plotting Using Tachyon 
     2The Tachyon 3D Ray Tracer 
     3 
     4Given any 3D graphics object one can compute a raytraced representation by typing 
     5\code{show(viewer='tachyon')}.  For example, we draw two translucent spheres that 
     6contain a red tube, and render the result using Tachyon. 
     7 
     8    sage: S = sphere(opacity=0.8, aspect_ratio=[1,1,1]) 
     9    sage: L = line3d([(0,0,0),(2,0,0)], thickness=10, color='red') 
     10    sage: M = S + S.translate((2,0,0)) + L 
     11    sage: M.show(viewer='tachyon') 
     12 
     13One can also directly control Tachyon, which gives a huge amount of 
     14flexibility.  For example, here we directly use Tachyon to draw 3 spheres 
     15on the coordinate axes.  Notice that the result is gorgeous: 
     16 
     17    sage: t = Tachyon(xres=500,yres=500, camera_center=(2,0,0)) 
     18    sage: t.light((4,3,2), 0.2, (1,1,1)) 
     19    sage: t.texture('t2', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) 
     20    sage: t.texture('t3', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,1,0)) 
     21    sage: t.texture('t4', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,0,1)) 
     22    sage: t.sphere((0,0.5,0), 0.2, 't2') 
     23    sage: t.sphere((0.5,0,0), 0.2, 't3') 
     24    sage: t.sphere((0,0,0.5), 0.2, 't4') 
     25    sage: t.show() 
     26 
    327 
    428AUTHOR: 
     
    5377 
    5478    EXAMPLES: 
    55     Three spheres on the coordinate axes: 
    56      
    57         sage: t = Tachyon(xres=500,yres=500, camera_center=(2,0,0)) 
    58         sage: t.light((4,3,2), 0.2, (1,1,1)) 
    59         sage: t.texture('t2', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) 
    60         sage: t.texture('t3', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,1,0)) 
    61         sage: t.texture('t4', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,0,1)) 
    62         sage: t.sphere((0,0.5,0), 0.2, 't2') 
    63         sage: t.sphere((0.5,0,0), 0.2, 't3') 
    64         sage: t.sphere((0,0,0.5), 0.2, 't4') 
    65         sage: t.show() 
    66  
    6779    Sphere's along the twisted cubic. 
    6880        sage: t = Tachyon(xres=512,yres=512, camera_center=(3,0.3,0)) 
Note: See TracChangeset for help on using the changeset viewer.