comparison main/plot/fill.m @ 0:6b33357c7561 octave-forge

Initial revision
author pkienzle
date Wed, 10 Oct 2001 19:54:49 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:6b33357c7561
1 ## Copyright (C) 1999 Daniel Heiserer
2 ##
3 ## This program is free software. It is distributed in the hope that it
4 ## will be useful, but WITHOUT ANY WARRANTY; without even the implied
5 ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
6 ## the GNU General Public License for more details.
7 ##
8 ## You should have received a copy of the GNU General Public License
9 ## along with this file; see the file COPYING. If not, write to the
10 ## Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
11 ## 02111-1307, USA.
12
13 ## FILL creates a pseudo-shaded patch
14 ## USAGE:
15 ## FILL(X,Y,C)
16 ## X x-coordinates of the patch
17 ## Y y-coordinates of the patch
18 ## C colour code as given by plot
19 ##
20 ## See also PATCH.
21
22 ## AUTHOR: Daniel Heiserer <Daniel.heiserer@physik.tu-muenchen.de>
23 ## 2001-01-16 Paul Kienzle
24 ## * reformatting, small speedup, unwind protect
25
26 function fill(x,y,c)
27
28 if nargin!=3
29 usage("fill (x,y,c)");
30 end
31
32 c=[c(1),';;'];
33
34 xs=size(x);
35 ys=size(y);
36
37 if ys~=xs
38 error('x and y have to have the same size');
39 end
40
41 ys=max(ys);
42 xs=max(xs);
43
44
45 ## What do we do, if we dont have a quad?
46
47 if ys<3
48 ## error('Area only defined for at least 3 coordinates')
49 ## should I care?
50 x(2)=x(1);
51 y(2)=y(1);
52 x(3)=x(2);
53 y(3)=y(2);
54 x(4)=x(3);
55 y(4)=y(3);
56 elseif ys==3
57 ## a triangle, merge node 4 to 1
58 x(4)=x(1);
59 y(4)=y(1);
60 elseif ys>4
61 ## ok we have to split it into multiple trias, quads look ugly
62 held = ishold;
63 unwind_protect
64 for jj=3:ys
65 fill([x(1),x(jj-1),x(jj)],[y(1),y(jj-1),y(jj)],c);
66 hold on;
67 end
68 unwind_protect_cleanup
69 if (!held) hold off; end;
70 end_unwind_protect
71 end
72
73
74 ## well as long as gnuplot has no fill function ...
75 ## we do it ourselves ....
76 ## maybe this looks really ugly if we have to fill
77 ## lots of triangles which should represent a polygon
78 ## but this approach has an excellent effort/work relationship
79 ## (maybe we are a little to economic here ;-)) ...
80 ## improveme!!!!
81 ## ok we assume our patch looks like this:
82 ##
83 ## 2+-------------------+3
84 ## | |
85 ## | |
86 ## | |
87 ## | |
88 ## | |
89 ## 1+-------------------+4
90 ##
91 ## and we want to have something like this:
92 ##
93 ## 2+-------------------+3
94 ## | | | | | | | | | | |
95 ## | | | | | | | | | | |
96 ## | | | | | | | | | | |
97 ## | | | | | | | | | | |
98 ## 1+-------------------+4
99 ##
100 ## for triangles we want to have only the grids 1-2-3
101
102 ## so we create a spacing from 1:4 and 2:3 using 1/increments
103 increments=50;
104 X_14=x(1):(x(4)-x(1))/increments:x(4);
105 X_23=x(2):(x(3)-x(2))/increments:x(3);
106 ## the same for Y
107 Y_14=y(1):(y(4)-y(1))/increments:y(4);
108 Y_23=y(2):(y(3)-y(2))/increments:y(3);
109 ## ok now assume x(1)==x(4) then the :: wouldn't generate anything
110 if (length(X_14)==0)
111 X_14=x(1)*ones(1,increments+1);
112 end
113 if (length(X_23)==0)
114 X_23=x(2)*ones(1,increments+1);
115 end
116 if (length(Y_14)==0)
117 Y_14=y(1)*ones(1,increments+1);
118 end
119 if (length(Y_23)==0)
120 Y_23=y(2)*ones(1,increments+1);
121 end
122
123 X=[X_23;X_14];
124 Y=[Y_23;Y_14];
125 idx=2:2:increments+1;
126 X(:,idx) = flipud(X(:,idx));
127 Y(:,idx) = flipud(Y(:,idx));
128 X=X(:);
129 Y=Y(:);
130
131 plot(X,Y,c)
132
133 endfunction