Mercurial > repos > public > sbplib
annotate +grid/Ti.m @ 364:44e9f7c16eb4 martin-thesis-plots
Closing Martins bad branch to the tune of 20 whip lashes.
author | Martin Almquist <martin.almquist@it.uu.se> |
---|---|
date | Tue, 20 Dec 2016 15:45:06 +0100 |
parents | 145b3b8c1e4e |
children |
rev | line source |
---|---|
0 | 1 classdef Ti |
2 properties | |
3 gs % {4}Curve | |
4 S % FunctionHandle(u,v) | |
5 end | |
6 | |
7 methods | |
8 % TODO function to label boundary names. | |
9 % function to find largest and smallest delta h in the grid. Maybe shouldnt live here | |
10 function obj = Ti(C1,C2,C3,C4) | |
11 obj.gs = {C1,C2,C3,C4}; | |
12 | |
13 g1 = C1.g; | |
14 g2 = C2.g; | |
15 g3 = C3.g; | |
16 g4 = C4.g; | |
17 | |
18 A = g1(0); | |
19 B = g2(0); | |
20 C = g3(0); | |
21 D = g4(0); | |
22 | |
23 function o = S_fun(u,v) | |
24 x1 = g1(u); | |
25 x2 = g2(v); | |
26 x3 = g3(1-u); | |
27 x4 = g4(1-v); | |
28 o1 = (1-v).*x1(1,:) + u.*x2(1,:) + v.*x3(1,:) + (1-u).*x4(1,:) ... | |
29 -((1-u)*(1-v).*A(1,:) + u*(1-v).*B(1,:) + u*v.*C(1,:) + (1-u)*v.*D(1,:)); | |
30 o2 = (1-v).*x1(2,:) + u.*x2(2,:) + v.*x3(2,:) + (1-u).*x4(2,:) ... | |
31 -((1-u)*(1-v).*A(2,:) + u*(1-v).*B(2,:) + u*v.*C(2,:) + (1-u)*v.*D(2,:)); | |
32 | |
33 o = [o1;o2]; | |
34 end | |
35 | |
36 obj.S = @S_fun; | |
37 end | |
38 | |
39 function [X,Y] = map(obj,u,v) | |
40 default_arg('v',u); | |
41 | |
42 if isscalar(u) | |
43 u = linspace(0,1,u); | |
44 end | |
45 | |
46 if isscalar(v) | |
47 v = linspace(0,1,v); | |
48 end | |
49 | |
50 S = obj.S; | |
51 | |
52 nu = length(u); | |
53 nv = length(v); | |
54 | |
55 X = zeros(nv,nu); | |
56 Y = zeros(nv,nu); | |
57 | |
58 u = rowVector(u); | |
59 v = rowVector(v); | |
60 | |
61 for i = 1:nv | |
62 p = S(u,v(i)); | |
63 X(i,:) = p(1,:); | |
64 Y(i,:) = p(2,:); | |
65 end | |
66 end | |
67 | |
68 function h = plot(obj,nu,nv) | |
69 S = obj.S; | |
70 | |
71 default_arg('nv',nu) | |
72 | |
73 u = linspace(0,1,nu); | |
74 v = linspace(0,1,nv); | |
75 | |
348
145b3b8c1e4e
Played around with Ti show and plot settings to create pretty pics for thesis.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
76 m = 1000; |
0 | 77 |
78 X = zeros(nu+nv,m); | |
79 Y = zeros(nu+nv,m); | |
80 | |
81 | |
82 t = linspace(0,1,m); | |
83 for i = 1:nu | |
84 p = S(u(i),t); | |
85 X(i,:) = p(1,:); | |
86 Y(i,:) = p(2,:); | |
87 end | |
88 | |
89 for i = 1:nv | |
90 p = S(t,v(i)); | |
91 X(i+nu,:) = p(1,:); | |
92 Y(i+nu,:) = p(2,:); | |
93 end | |
94 | |
95 h = line(X',Y'); | |
96 end | |
97 | |
98 | |
99 function h = show(obj,nu,nv) | |
100 default_arg('nv',nu) | |
101 S = obj.S; | |
102 | |
103 if(nu>2 || nv>2) | |
104 h_grid = obj.plot(nu,nv); | |
348
145b3b8c1e4e
Played around with Ti show and plot settings to create pretty pics for thesis.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
105 % set(h_grid,'Color',[0 0.4470 0.7410]); |
145b3b8c1e4e
Played around with Ti show and plot settings to create pretty pics for thesis.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
106 set(h_grid,'Color',[0 0 0]); |
145b3b8c1e4e
Played around with Ti show and plot settings to create pretty pics for thesis.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
107 set(h_grid,'LineWidth',1); |
0 | 108 end |
109 | |
110 h_bord = obj.plot(2,2); | |
348
145b3b8c1e4e
Played around with Ti show and plot settings to create pretty pics for thesis.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
111 % set(h_bord,'Color',[0.8500 0.3250 0.0980]); |
145b3b8c1e4e
Played around with Ti show and plot settings to create pretty pics for thesis.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
112 set(h_bord,'Color',[0 0 0]); |
145b3b8c1e4e
Played around with Ti show and plot settings to create pretty pics for thesis.
Martin Almquist <martin.almquist@it.uu.se>
parents:
0
diff
changeset
|
113 set(h_bord,'LineWidth',3); |
0 | 114 end |
115 | |
116 | |
117 % TRANSFORMATIONS | |
118 function ti = translate(obj,a) | |
119 gs = obj.gs; | |
120 | |
121 for i = 1:length(gs) | |
122 new_gs{i} = gs{i}.translate(a); | |
123 end | |
124 | |
125 ti = grid.Ti(new_gs{:}); | |
126 end | |
127 | |
128 % Mirrors the Ti so that the resulting Ti is still left handed. | |
129 % (Corrected by reversing curves and switching e and w) | |
130 function ti = mirror(obj, a, b) | |
131 gs = obj.gs; | |
132 | |
133 new_gs = cell(1,4); | |
134 | |
135 new_gs{1} = gs{1}.mirror(a,b).reverse(); | |
136 new_gs{3} = gs{3}.mirror(a,b).reverse(); | |
137 new_gs{2} = gs{4}.mirror(a,b).reverse(); | |
138 new_gs{4} = gs{2}.mirror(a,b).reverse(); | |
139 | |
140 ti = grid.Ti(new_gs{:}); | |
141 end | |
142 | |
143 function ti = rotate(obj,a,rad) | |
144 gs = obj.gs; | |
145 | |
146 for i = 1:length(gs) | |
147 new_gs{i} = gs{i}.rotate(a,rad); | |
148 end | |
149 | |
150 ti = grid.Ti(new_gs{:}); | |
151 end | |
152 | |
153 function ti = rotate_edges(obj,n); | |
154 new_gs = cell(1,4); | |
155 for i = 0:3 | |
156 new_i = mod(i - n,4); | |
157 new_gs{new_i+1} = obj.gs{i+1}; | |
158 end | |
159 ti = grid.Ti(new_gs{:}); | |
160 end | |
161 end | |
162 | |
163 methods(Static) | |
164 function obj = points(p1, p2, p3, p4) | |
165 g1 = grid.Curve.line(p1,p2); | |
166 g2 = grid.Curve.line(p2,p3); | |
167 g3 = grid.Curve.line(p3,p4); | |
168 g4 = grid.Curve.line(p4,p1); | |
169 | |
170 obj = grid.Ti(g1,g2,g3,g4); | |
171 end | |
172 | |
173 function label(varargin) | |
174 if nargin == 2 && ischar(varargin{2}) | |
175 label_impl(varargin{:}); | |
176 else | |
177 for i = 1:length(varargin) | |
178 label_impl(varargin{i},inputname(i)); | |
179 end | |
180 end | |
181 | |
182 | |
183 function label_impl(ti,str) | |
184 S = ti.S; | |
185 | |
186 pc = S(0.5,0.5); | |
187 | |
188 margin = 0.1; | |
189 pw = S( margin, 0.5); | |
190 pe = S(1-margin, 0.5); | |
191 ps = S( 0.5, margin); | |
192 pn = S( 0.5, 1-margin); | |
193 | |
194 | |
195 ti.show(2,2); | |
196 grid.place_label(pc,str); | |
197 grid.place_label(pw,'w'); | |
198 grid.place_label(pe,'e'); | |
199 grid.place_label(ps,'s'); | |
200 grid.place_label(pn,'n'); | |
201 end | |
202 end | |
203 end | |
204 end |