Mercurial > octave-nkf
annotate doc/interpreter/geometryimages.m @ 20351:d8992a16643c
doc: Clean up m-files which generate images for Manual.
* geometryimages.m, interpimages.m, plotimages.m, sparseimages.m,
splineimages.m: Use the same style throughout the mi-files.
Obey Octave coding conventions.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 09 Jul 2015 21:38:57 -0700 |
parents | c3c1fb44f9b5 |
children | b439ccc9a162 |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19627
diff
changeset
|
1 ## Copyright (C) 2007-2015 David Bateman |
7018 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
19 function geometryimages (d, nm, typ) |
19751
606b05352351
Backout cset 59ad278cfb98, use gnuplot for building doc images.
Rik <rik@octave.org>
parents:
19742
diff
changeset
|
20 graphics_toolkit ("gnuplot"); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
21 set_print_size (); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
22 hide_output (); |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
23 outfile = fullfile (d, [nm "." typ]); |
7257 | 24 if (strcmp (typ, "png")) |
25 set (0, "defaulttextfontname", "*"); | |
26 endif | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
27 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
28 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
29 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
30 d_typ = ["-d" typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
31 endif |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
32 |
16170
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
33 if (! __have_feature__ ("QHULL") |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
34 && any (strcmp (nm, {"voronoi", "griddata", "convhull", "delaunay", ... |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
35 "triplot"}))) |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
36 sombreroimage (nm, typ, d_typ); |
7262 | 37 elseif (strcmp (typ, "txt")) |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
38 image_as_txt (d, nm); |
6855 | 39 elseif (strcmp (nm, "voronoi")) |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
40 rand ("state", 9); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
41 x = rand (10, 1); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
42 y = rand (10, 1); |
6832 | 43 tri = delaunay (x, y); |
44 [vx, vy] = voronoi (x, y, tri); | |
45 triplot (tri, x, y, "b"); | |
46 hold on; | |
47 plot (vx, vy, "r"); | |
48 [r, c] = tri2circ (tri(end,:), x, y); | |
49 pc = [-1:0.01:1]; | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
50 xc = r * sin (pi*pc) + c(1); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
51 yc = r * cos (pi*pc) + c(2); |
6832 | 52 plot (xc, yc, "g-", "LineWidth", 3); |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
53 axis ([0, 1, 0, 1]); |
6832 | 54 legend ("Delaunay Triangulation", "Voronoi Diagram"); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
55 print (outfile, d_typ); |
6832 | 56 elseif (strcmp (nm, "triplot")) |
57 rand ("state", 2) | |
58 x = rand (20, 1); | |
59 y = rand (20, 1); | |
60 tri = delaunay (x, y); | |
61 triplot (tri, x, y); | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
62 print (outfile, d_typ); |
6832 | 63 elseif (strcmp (nm, "griddata")) |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
64 rand ("state", 1); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
65 x = 2 * rand (1000,1) - 1; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
66 y = 2 * rand (size (x)) - 1; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
67 z = sin (2 * (x.^2 + y.^2)); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
68 [xx,yy] = meshgrid (linspace (-1,1,32)); |
20250
4e15a4c331e7
doc: Fix griddata example to new calling convention
Mike Miller <mtmiller@octave.org>
parents:
19751
diff
changeset
|
69 zz = griddata (x, y, z, xx, yy); |
4e15a4c331e7
doc: Fix griddata example to new calling convention
Mike Miller <mtmiller@octave.org>
parents:
19751
diff
changeset
|
70 mesh (xx, yy, zz); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
71 print (outfile, d_typ); |
6832 | 72 elseif (strcmp (nm, "convhull")) |
73 x = -3:0.05:3; | |
74 y = abs (sin (x)); | |
75 k = convhull (x, y); | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
76 plot (x(k),y(k),'r-', x,y,'b+'); |
6832 | 77 axis ([-3.05, 3.05, -0.05, 1.05]); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
78 print (outfile, d_typ); |
6832 | 79 elseif (strcmp (nm, "delaunay")) |
80 rand ("state", 1); | |
6847 | 81 x = rand (1, 10); |
82 y = rand (1, 10); | |
6832 | 83 T = delaunay (x, y); |
84 X = [ x(T(:,1)); x(T(:,2)); x(T(:,3)); x(T(:,1)) ]; | |
85 Y = [ y(T(:,1)); y(T(:,2)); y(T(:,3)); y(T(:,1)) ]; | |
86 axis ([0, 1, 0, 1]); | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
87 plot (X,Y,"b", x,y,"r*"); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
88 print (outfile, d_typ); |
6847 | 89 elseif (strcmp (nm, "inpolygon")) |
90 randn ("state", 2); | |
91 x = randn (100, 1); | |
92 y = randn (100, 1); | |
93 vx = cos (pi * [-1 : 0.1: 1]); | |
94 vy = sin (pi * [-1 : 0.1 : 1]); | |
95 in = inpolygon (x, y, vx, vy); | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
96 plot (vx, vy, x(in), y(in), "r+", x(!in), y(!in), "bo"); |
6847 | 97 axis ([-2, 2, -2, 2]); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
98 print (outfile, d_typ); |
6832 | 99 else |
100 error ("unrecognized plot requested"); | |
101 endif | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
102 hide_output (); |
6832 | 103 endfunction |
104 | |
105 function [r, c] = tri2circ (tri, xx, yy) | |
106 x = xx(tri); | |
107 y = yy(tri); | |
108 m = (y(1:end-1) - y(2:end)) ./ (x(1:end-1) - x(2:end)); | |
109 xc = (prod(m) .* (y(1) - y(end)) + m(end)*(x(1)+x(2)) - m(1)*(x(2)+x(3))) ... | |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
110 ./ (2 * (m(end) - m(1))); |
6832 | 111 yc = - (xc - (x(2) + x(3))./2) ./ m(end) + (y(2) + y(3)) / 2; |
112 c = [xc, yc]; | |
113 r = sqrt ((xc - x(1)).^2 + (yc - y(1)).^2); | |
114 endfunction | |
115 | |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
116 function sombreroimage (nm, typ, d_typ) |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
117 if (strcmp (typ, "txt")) |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
118 fid = fopen ([nm ".txt"], "wt"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
119 fputs (fid, "+-----------------------------+\n"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
120 fputs (fid, "| Image unavailable because |\n"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
121 fputs (fid, "| of a missing QHULL library. |\n"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
122 fputs (fid, "+-----------------------------+\n"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
123 fclose (fid); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
124 return; |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
125 else |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
126 hide_output (); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
127 [x, y, z] = sombrero (); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
128 unwind_protect |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
129 mesh (x, y, z); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
130 title ("Sorry, graphics not available because Octave was\\ncompiled without the QHULL library."); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
131 unwind_protect_cleanup |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
132 print (outfile, d_typ); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
133 hide_output (); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
134 end_unwind_protect |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
135 endif |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
136 endfunction |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
137 |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
138 function set_print_size () |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
139 image_size = [5.0, 3.5]; # in inches, 16:9 format |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
140 border = 0; # For postscript use 50/72 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
141 set (0, "defaultfigurepapertype", "<custom>"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
142 set (0, "defaultfigurepaperorientation", "landscape"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
143 set (0, "defaultfigurepapersize", image_size + 2*border); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
144 set (0, "defaultfigurepaperposition", [border, border, image_size]); |
6832 | 145 endfunction |
146 | |
147 ## Use this function before plotting commands and after every call to | |
148 ## print since print() resets output to stdout (unfortunately, gnpulot | |
149 ## can't pop output as it can the terminal type). | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
150 function hide_output () |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
151 hf = figure (1); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
152 set (hf, "visible", "off"); |
6855 | 153 endfunction |
7262 | 154 |
155 ## generate something for the texinfo @image command to process | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
20250
diff
changeset
|
156 function image_as_txt (d, nm) |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
157 fid = fopen (fullfile (d, [nm ".txt"]), "wt"); |
7262 | 158 fputs (fid, "\n"); |
159 fputs (fid, "+---------------------------------+\n"); | |
160 fputs (fid, "| Image unavailable in text mode. |\n"); | |
161 fputs (fid, "+---------------------------------+\n"); | |
162 fclose (fid); | |
163 endfunction | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
164 |