Changeset 8085:36a142494ced
- Timestamp:
- 01/17/08 23:29:54 (5 years ago)
- Branch:
- default
- Location:
- sage/plot
- Files:
-
- 1 added
- 8 edited
-
misc.py (added)
-
plot3d/bugs.txt (modified) (1 diff)
-
plot3d/examples.py (modified) (1 diff)
-
plot3d/list_plot3d.py (modified) (1 diff)
-
plot3d/parametric_plot3d.py (modified) (7 diffs)
-
plot3d/platonic.py (modified) (10 diffs)
-
plot3d/plot3d.py (modified) (3 diffs)
-
plot3d/shapes2.py (modified) (9 diffs)
-
tachyon.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/plot/plot3d/bugs.txt
r7969 r8085 1 We 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 6 NOTE: The sphere above have holes in them. This is a \emph{bug} in jmol. 7 8 1 9 * Only the last jmol 3d image is displayed, e..g., in one notebook cell 2 10 sage: x, y = var('x,y') -
sage/plot/plot3d/examples.py
r7969 r8085 1 """2 EXAMPLES of 3d Plots: 1 r""" 2 Introduction. 3 3 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) 8 5 """ 9 6 -
sage/plot/plot3d/list_plot3d.py
r7962 r8085 1 1 """ 2 3d list plots2 List Plots 3 3 """ 4 4 -
sage/plot/plot3d/parametric_plot3d.py
r8035 r8085 1 1 """ 2 3dParametric Plots2 Parametric Plots 3 3 """ 4 4 … … 6 6 from shapes2 import line3d 7 7 from texture import Texture 8 from sage.plot.misc import ensure_subs 8 9 9 10 def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", **kwds): 10 """11 r""" 11 12 Return a parametric three-dimensional space curve or surface. 12 13 13 INPUTS:14 14 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}$ 17 18 are real numbers 18 19 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 u20 \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$ 21 22 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: 29 31 f -- a 3-tuple of functions or expressions 30 32 urange -- a 2-tuple (u_min, u_max) or a 3-tuple (u, u_min, u_max) … … 37 39 38 40 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 40 43 not evaluate to a real number are skipped. 41 *Currently for a surface f_x, f_y, and f_z have to be defined44 \item Currently for a surface f_x, f_y, and f_z have to be defined 42 45 everywhere. This will change. 46 \end{enumerate} 43 47 44 48 EXAMPLES: 45 49 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: 48 52 sage: parametric_plot3d( (sin, cos, lambda u: u/10), (0, 20)) 49 53 … … 51 55 that sends u to u/10. 52 56 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: 54 58 sage: u = var('u') 55 59 sage: parametric_plot3d( (sin(u), cos(u), u/10), (u, 0, 20)) 56 60 57 3.We draw a parametric surface using 3 Python functions (defined using61 \item We draw a parametric surface using 3 Python functions (defined using 58 62 lambda): 59 63 sage: f = (lambda u,v: cos(u), lambda u,v: sin(u)+cos(v), lambda u,v: sin(v)) 60 64 sage: parametric_plot3d(f, (0, 2*pi), (-pi, pi)) 61 65 62 4.The same surface, but where the defining functions are symbolic:66 \item The same surface, but where the defining functions are symbolic: 63 67 sage: u, v = var('u,v') 64 68 sage: parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi)) 65 69 66 70 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} 68 74 69 75 We call the space curve function but with polynomials instead of … … 132 138 133 139 def parametric_plot3d_curve(f, urange, plot_points, **kwds): 140 r""" 141 This function is used internally by the \code{parametric_plot3d} command. 142 """ 134 143 from sage.plot.plot import var_and_list_of_values 135 144 plot_points = int(plot_points) … … 159 168 160 169 def parametric_plot3d_surface(f, urange, vrange, plot_points, **kwds): 170 r""" 171 This function is used internally by the \code{parametric_plot3d} command. 172 """ 161 173 if not isinstance(plot_points, (list, tuple)) or len(plot_points) != 2: 162 174 raise ValueError, "plot_points must be a tuple of length 2" … … 188 200 189 201 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 SR194 return SR(f)195 return f -
sage/plot/plot3d/platonic.py
r8063 r8085 1 1 r""" 2 Methods for creating the five platonic solids.2 Platonic Solids. 3 3 4 4 EXAMPLES: 5 5 The 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') 7 9 sage: G.show(aspect_ratio=[1,1,1]) 8 10 9 11 All 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) 11 16 sage: G.show(aspect_ratio=[1,1,1]) 12 17 … … 71 76 A 3d tetrahedron. 72 77 73 INPUT S:78 INPUT: 74 79 center -- (default: (0,0,0)) 75 80 size -- (default: 1) … … 114 119 def cube(center=(0,0,0), size=1, color=None, frame_thickness=0, frame_color=None, **kwds): 115 120 """ 116 A 3 dcube centered at the origin with default side lengths 1.117 118 INPUT S:121 A 3D cube centered at the origin with default side lengths 1. 122 123 INPUT: 119 124 center -- (default: (0,0,0)) 120 125 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 126 133 opacity -- (default: 1) if less than 1 then is transparent 127 134 … … 140 147 141 148 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]) 143 151 144 152 Non-square cubes (boxes): … … 147 155 148 156 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]) 150 159 151 160 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) 153 163 sage: c 154 164 … … 173 183 174 184 def octahedron(center=(0,0,0), size=1, **kwds): 175 """185 r""" 176 186 Return an octahedron. 177 187 178 INPUT S:188 INPUT: 179 189 center -- (default: (0,0,0)) 180 190 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) 188 199 """ 189 200 return prep(Box(1,1,1).dual(**kwds), center, size, kwds) 190 201 191 202 def dodecahedron(center=(0,0,0), size=1, **kwds): 192 """203 r""" 193 204 A dodecahedron. 194 205 195 INPUT S:206 INPUT: 196 207 center -- (default: (0,0,0)) 197 208 size -- (default: 1) 198 color -- a string that describes a color; this can also be a list of 3-tuples or199 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. 201 212 opacity -- (default: 1) if less than 1 then is transparent 202 213 … … 206 217 207 218 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') 209 221 210 222 CONSTRUCTION: … … 223 235 $P_3 = \left(-\frac{1}{2}t, \frac{\sqrt{3}}{2}t, \sqrt{1-t^2}\right)$ 224 236 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$. 226 240 227 241 Now we have 6 points $R_1, ..., R_6$ to close the three top pentagons. … … 279 293 280 294 def icosahedron(center=(0,0,0), size=1, **kwds): 281 """295 r""" 282 296 An icosahedron. 283 297 284 INPUT S:298 INPUT: 285 299 center -- (default: (0,0,0)) 286 300 size -- (default: 1) 287 color -- a string that describes a color; this can also be a list of 3-tuples or288 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. 290 304 opacity -- (default: 1) if less than 1 then is transparent 291 305 … … 294 308 295 309 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]) 297 312 """ 298 313 return prep(dodecahedron().dual(**kwds), center, size, kwds) -
sage/plot/plot3d/plot3d.py
r8064 r8085 1 1 r""" 2 Functions for 3d plotting with the new graphics model.2 Plotting Functions. 3 3 4 4 EXAMPLES: … … 36 36 -- Robert Bradshaw 2007-08: initial version of this file 37 37 -- William Stein 2007-12, 2008-01: improving 3d plotting 38 39 TODO:40 -- smooth triangles41 38 """ 39 40 41 #TODO: 42 # -- smooth triangles 42 43 43 44 #***************************************************************************** … … 110 111 Adaptive 3d plotting of a function of two variables. 111 112 112 INPUT S:113 INPUT: 113 114 f -- a symbolic function or a Python function of 3 variables. 114 115 x_range -- x range of values: 2-tuple (xmin, xmax) or 3-tuple (x,xmin,xmax) -
sage/plot/plot3d/shapes2.py
r7976 r8085 1 """ 2 Lines, Frames, Spheres, Points, Dots, and Text 3 """ 4 1 5 import math 2 6 import shapes … … 15 19 16 20 def line3d(points, thickness=1, radius=None, arrow_head=False, **kwds): 17 """21 r""" 18 22 Draw a 3d line joining a sequence of points. 19 23 … … 40 44 41 45 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)]) 43 48 """ 44 49 if len(points) < 2: … … 205 210 206 211 def sphere(center=(0,0,0), size=1, **kwds): 207 """212 r""" 208 213 Return a plot of a sphere of radius size centered at $(x,y,z)$. 209 214 … … 217 222 218 223 Two sphere's touching: 219 s phere(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]) 220 225 221 226 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) 223 229 224 230 We draw a transparent sphere on a saddle. … … 233 239 234 240 def text3d(txt, (x,y,z), **kwds): 235 """241 r""" 236 242 Display 3d text. 237 243 … … 250 256 251 257 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]]) 253 260 """ 254 261 if not kwds.has_key('color') and not kwds.has_key('rgbcolor'): … … 304 311 305 312 class Line(PrimitiveObject): 306 """313 r""" 307 314 Draw a 3d line joining a sequence of points. 308 315 309 316 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}. 311 318 312 319 INPUT: 313 320 points -- list of points to pass through 314 321 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 317 325 arrow_head -- if True make this curve into an arrow 318 326 319 327 EXAMPLES: 320 328 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: 324 333 sage: Line([(0,0,0),(1,0,0),(2,1,0),(0,1,0)], corner_cutoff=0) 325 334 """ … … 454 463 Plot a point or list of points in 3d space. 455 464 456 INPUT S:465 INPUT: 457 466 v -- a point or list of points 458 467 size -- (default: 1) size of the point (or points) -
sage/plot/tachyon.py
r7541 r8085 1 1 r""" 2 3D Plotting Using Tachyon 2 The Tachyon 3D Ray Tracer 3 4 Given 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 6 contain 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 13 One can also directly control Tachyon, which gives a huge amount of 14 flexibility. For example, here we directly use Tachyon to draw 3 spheres 15 on 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 3 27 4 28 AUTHOR: … … 53 77 54 78 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 67 79 Sphere's along the twisted cubic. 68 80 sage: t = Tachyon(xres=512,yres=512, camera_center=(3,0.3,0))
Note: See TracChangeset
for help on using the changeset viewer.
