0001 function fwd_mdl = deform_cylinder( fwd_mdl, geo);
0002
0003
0004
0005
0006
0007 if isstr(fwd_mdl) && strcmp(fwd_mdl,'UNIT_TEST'); do_unit_test; return; end
0008
0009 NODE= fwd_mdl.nodes';
0010 a_max= size(geo.xy,1);
0011 ab_geo=sqrt(sum(([ geo.xy; geo.xy(1,:) ]').^2)');
0012 nn= zeros(size(NODE));
0013 for i=1:size(NODE,2);
0014 angle = rem(a_max*atan2( NODE(2,i), ...
0015 NODE(1,i) )/2/pi+a_max,a_max)+1;
0016 fl_angl = floor(angle + eps );
0017 fac=( (fl_angl + 1 - angle) * ab_geo(fl_angl) + ...
0018 (angle - fl_angl) * ab_geo(fl_angl + 1) );
0019 nn(1:2,i)= NODE(1:2,i)* fac;
0020 end
0021 if size(nn,1) == 3;
0022 nn(3,:) = NODE(3,:)*geo.z_mag;
0023 end
0024
0025 xyz_expand = 1;
0026 fwd_mdl.nodes = nn'*eye(xyz_expand);
0027
0028 function fmdl_out = deform_cylinder2( fmdl, deform_pararms)
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 if isstr(fmdl) && strcmp(fmdl,'UNIT_TEST'); do_unit_test;return;end
0054
0055 pp = proc_params( deform_pararms, fmdl )
0056
0057 function pp = proc_params( deform_pararms, fmdl )
0058 d = size(fmdl.nodes,2);
0059 if isfield(deform_pararms,'axes')
0060 dpax = deform_pararms.axes;
0061 [r,c] = size(dpax);
0062 if r==1;
0063 pp.axes = sparse(dpax,1:c,1,c,c);
0064 else
0065 pp.axes = sparse(dpax);
0066
0067 end
0068 else
0069 pp.axes = speye(d);
0070 end
0071
0072 if isfield(deform_pararms,'mode')
0073 switch deform_pararms.mode
0074 case 'add'; pp.mode = 1;
0075 case 'mul'; pp.mode = 2;
0076 otherwise; error(['deform mode not understood']);
0077 end
0078 else
0079 pp.mode = 2;
0080 end
0081
0082 if isfield(deform_params,'xycentre')
0083 pp.xctr = deform_pararms.xycentre(1);
0084 pp.yctr = deform_pararms.xycentre(2);
0085 else
0086 pp.xctr = 0;
0087 pp.yctr = 0;
0088 end
0089
0090
0091 xy= deform_pararms.xyspecpos;
0092 [pp.th_s,pp.r_s] = cart2pol(xy(:,1)-pp.xctr, ...
0093 xy(:,2)-pp.yctr);
0094
0095
0096 for i=1:length(fmdl.electrode);
0097 enodes = fmdl.electrode(i).nodes;
0098 fepos(i,:) = mean(fmdl.nodes(enodes,:),1);
0099 end
0100
0101 [pp.th_e,pp.r_e] = cart2pol(fepos(:,1)-pp.xctr, ...
0102 fepos(:,2)-pp.yctr);
0103
0104 function deform(fmdl, pp);
0105 th = mean([the,thm],2);
0106 dr = re-rm;
0107 dr = [dr;dr;dr];
0108 th = [th-2*pi;th;th+2*pi];
0109 [th,idx]=sort(th); dr= dr(idx);
0110 tpf = polyfit(th,idx,10);
0111 plot(th,dr,'*');
0112
0113 [thn,rn] = cart2pol( fmdl.nodes(:,2)-yc, fmdl.nodes(:,3)-zc );
0114 drn = interp1(th,dr,thn);
0115 rn = rn + drn;
0116 [nodesy, nodesz] = pol2cart(thn,rn);
0117 fmdl.nodes(:,2:3) = [nodesy+yc, nodesz+zc];
0118
0119 hh=plot(elec_pos(:,2),elec_pos(:,3),'*-',fepos(:,2),fepos(:,3),'o-');
0120 set(hh,'LineWidth',2);
0121 hold on;
0122 f1ml = fmdl; f1ml.nodes = f1ml.nodes(:,[2,3,1]);
0123 show_fem(f1ml);
0124 hold off;
0125
0126 function do_unit_test
0127 fmdl= ng_mk_cyl_models(1,0,[]);
0128 th = linspace(0,2*pi,50)';
0129 geo.xy=[sin(th),2*cos(th)];
0130 geo.z_mag = 10;
0131 show_fem(deform_cylinder(fmdl,geo));
0132 view(2);