Mercurial > octave
annotate doc/interpreter/geometryimages.m @ 9912:e9fe12c1b0c0
Set default papersize to the desired imagesize
Set default paperorientation to landscape to stop warning message
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Fri, 04 Dec 2009 09:45:15 -0800 |
parents | eb63fbe60fab |
children | e76d8c767584 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2007, 2008 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 | |
6832 | 19 function geometryimages (nm, typ) |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
20 set_print_size (); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
21 hide_output (); |
7257 | 22 if (strcmp (typ, "png")) |
23 set (0, "defaulttextfontname", "*"); | |
24 endif | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 |
6878 | 26 if (isempty (findstr (octave_config_info ("DEFS"), "HAVE_QHULL")) |
27 && (strcmp (nm, "voronoi") || strcmp (nm, "griddata") | |
28 || strcmp (nm, "convhull") || strcmp (nm, "delaunay") | |
29 || strcmp (nm, "triplot"))) | |
6855 | 30 sombreroimage (nm, typ); |
7262 | 31 elseif (strcmp (typ, "txt")) |
32 image_as_txt (nm); | |
6855 | 33 elseif (strcmp (nm, "voronoi")) |
6832 | 34 rand("state",9); |
35 x = rand(10,1); | |
36 y = rand(10,1); | |
37 tri = delaunay (x, y); | |
38 [vx, vy] = voronoi (x, y, tri); | |
39 triplot (tri, x, y, "b"); | |
40 hold on; | |
41 plot (vx, vy, "r"); | |
42 [r, c] = tri2circ (tri(end,:), x, y); | |
43 pc = [-1:0.01:1]; | |
44 xc = r * sin(pi*pc) + c(1); | |
45 yc = r * cos(pi*pc) + c(2); | |
46 plot (xc, yc, "g-", "LineWidth", 3); | |
47 axis([0, 1, 0, 1]); | |
48 legend ("Delaunay Triangulation", "Voronoi Diagram"); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7262
diff
changeset
|
49 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6832 | 50 elseif (strcmp (nm, "triplot")) |
51 rand ("state", 2) | |
52 x = rand (20, 1); | |
53 y = rand (20, 1); | |
54 tri = delaunay (x, y); | |
55 triplot (tri, x, y); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7262
diff
changeset
|
56 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6832 | 57 elseif (strcmp (nm, "griddata")) |
58 rand("state",1); | |
59 x=2*rand(1000,1)-1; | |
60 y=2*rand(size(x))-1; | |
61 z=sin(2*(x.^2+y.^2)); | |
62 [xx,yy]=meshgrid(linspace(-1,1,32)); | |
63 griddata(x,y,z,xx,yy); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7262
diff
changeset
|
64 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6832 | 65 elseif (strcmp (nm, "convhull")) |
66 x = -3:0.05:3; | |
67 y = abs (sin (x)); | |
68 k = convhull (x, y); | |
69 plot (x(k),y(k),'r-',x,y,'b+'); | |
70 axis ([-3.05, 3.05, -0.05, 1.05]); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7262
diff
changeset
|
71 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6832 | 72 elseif (strcmp (nm, "delaunay")) |
73 rand ("state", 1); | |
6847 | 74 x = rand (1, 10); |
75 y = rand (1, 10); | |
6832 | 76 T = delaunay (x, y); |
77 X = [ x(T(:,1)); x(T(:,2)); x(T(:,3)); x(T(:,1)) ]; | |
78 Y = [ y(T(:,1)); y(T(:,2)); y(T(:,3)); y(T(:,1)) ]; | |
79 axis ([0, 1, 0, 1]); | |
80 plot(X, Y, "b", x, y, "r*"); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7262
diff
changeset
|
81 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6847 | 82 elseif (strcmp (nm, "inpolygon")) |
83 randn ("state", 2); | |
84 x = randn (100, 1); | |
85 y = randn (100, 1); | |
86 vx = cos (pi * [-1 : 0.1: 1]); | |
87 vy = sin (pi * [-1 : 0.1 : 1]); | |
88 in = inpolygon (x, y, vx, vy); | |
89 plot(vx, vy, x(in), y(in), "r+", x(!in), y(!in), "bo"); | |
90 axis ([-2, 2, -2, 2]); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7262
diff
changeset
|
91 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)) |
6832 | 92 else |
93 error ("unrecognized plot requested"); | |
94 endif | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
95 hide_output (); |
6832 | 96 endfunction |
97 | |
98 function [r, c] = tri2circ (tri, xx, yy) | |
99 x = xx(tri); | |
100 y = yy(tri); | |
101 m = (y(1:end-1) - y(2:end)) ./ (x(1:end-1) - x(2:end)); | |
102 xc = (prod(m) .* (y(1) - y(end)) + m(end)*(x(1)+x(2)) - m(1)*(x(2)+x(3))) ... | |
103 ./ (2 * (m(end) - m(1))); | |
104 yc = - (xc - (x(2) + x(3))./2) ./ m(end) + (y(2) + y(3)) / 2; | |
105 c = [xc, yc]; | |
106 r = sqrt ((xc - x(1)).^2 + (yc - y(1)).^2); | |
107 endfunction | |
108 | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
109 function set_print_size () |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
110 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
|
111 border = 0; # For postscript use 50/72 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
112 set (0, "defaultfigurepapertype", "<custom>"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
113 set (0, "defaultfigurepaperorientation", "landscape"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
114 set (0, "defaultfigurepapersize", image_size + 2*border); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
115 set (0, "defaultfigurepaperposition", [border, border, image_size]); |
6832 | 116 endfunction |
117 | |
118 ## Use this function before plotting commands and after every call to | |
119 ## print since print() resets output to stdout (unfortunately, gnpulot | |
120 ## 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
|
121 function hide_output () |
6832 | 122 f = figure (1); |
123 set (f, "visible", "off"); | |
124 endfunction | |
6855 | 125 |
126 function sombreroimage (nm, typ) | |
127 if (strcmp (typ, "txt")) | |
128 fid = fopen (sprintf ("%s.txt", nm), "wt"); | |
129 fputs (fid, "+-----------------------------+\n"); | |
130 fputs (fid, "| Image unavailable because |\n"); | |
131 fputs (fid, "| of a missing QHULL library. |\n"); | |
132 fputs (fid, "+-----------------------------+\n"); | |
133 fclose (fid); | |
134 return; | |
135 else ## if (!strcmp (typ, "txt")) | |
136 | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
137 hide_output (); |
6855 | 138 |
139 x = y = linspace (-8, 8, 41)'; | |
140 [xx, yy] = meshgrid (x, y); | |
141 r = sqrt (xx .^ 2 + yy .^ 2) + eps; | |
142 z = sin (r) ./ r; | |
143 unwind_protect | |
144 mesh (x, y, z); | |
145 title ("Sorry, graphics not available because octave was\\ncompiled without the QHULL library."); | |
146 unwind_protect_cleanup | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7262
diff
changeset
|
147 print (cstrcat (nm, ".", typ), cstrcat ("-d", typ)); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
148 hide_output (); |
6855 | 149 end_unwind_protect |
150 endif | |
151 endfunction | |
7262 | 152 |
153 ## generate something for the texinfo @image command to process | |
154 function image_as_txt(nm) | |
155 fid = fopen (sprintf ("%s.txt", nm), "wt"); | |
156 fputs (fid, "\n"); | |
157 fputs (fid, "+---------------------------------+\n"); | |
158 fputs (fid, "| Image unavailable in text mode. |\n"); | |
159 fputs (fid, "+---------------------------------+\n"); | |
160 fclose (fid); | |
161 endfunction |