rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
points_trafo.m
1 function pts_transformed=points_trafo(model,glob)
2 %function pts_transformed=points_trafo(model,glob)
3 %
4 % function transforming points according to which macro-triangle they belong
5 % to.
6 %
7 % input:
8 % model
9 % glob: n-by-2 list of the points which shall be transformed
10 %
11 % ouput:
12 % pts_transformed: n-by-2 list of transformed points
13 %
14 % needed fields in model:
15 % mu_names
16 %
17 %
18 % Oliver Zeeb, 16.02.11
19 
20 nr_macro_tri = size(model.tmacro,1);
21 pmacro_ref = model.pmacro; % points of the reference macrogrid
22 tmacro = model.tmacro;
23 
24 % use the mus for setting the new macrogrid-points
25 pmacro_reshaped = model.pmacro; % coordinates of the reshaped macrogrid
26 % old: 12.05.11: funktioniert so nur, wenn alle punkte parameter sind!
27 % for k=1:nr_mus/2 % nr_mus = length(model.mu_names) should be even
28 % x = getfield(model, model.mu_names{k});
29 % y = getfield(model, model.mu_names{k+nr_mus/2});
30 % pmacro_reshaped(k,:) = [x,y];
31 % end
32 %neu: 12.05.11:
33 for k=1:model.nr_macro_car_points
34  x = getfield(model, ['x',num2str(k)]);
35  y = getfield(model, ['y',num2str(k)]);
36  pmacro_reshaped(k,:) = [x,y];
37 end
38 %ende neu: 12.05.11
39 
40 %now the reshaped macropoints are set
41 
42 if isequal(pmacro_reshaped,pmacro_ref) %no points were changed, still the original grid
43  pts_transformed=glob;
44  disp(' mu=mu_ref: no transformation needed!')
45 else %some macropoints were changed, so the points mus be transformed
46  %get the affine transformation for every macrogrid
47  disp(' transforming points... ')
48  C = zeros(2,nr_macro_tri);
49  G = zeros(2,2,nr_macro_tri);
50  for k=1:nr_macro_tri
51  tria_pts_ref = pmacro_ref(tmacro(k,:),:);
52  tria_pts_reshaped = pmacro_reshaped(tmacro(k,:),:);
53  [C(:,k), G(:,:,k)] = aff_trafo_coef(tria_pts_ref, tria_pts_reshaped);
54  end
55  %which point of the microgrid belongs to which macrotriangle?
56  pmic2tmac = pmicro2tmacro([glob(:,1),glob(:,2)], model);
57 
58  %transform the points
59  pts_transformed = [glob(:,1)'; glob(:,2)'];
60  for k = 1:nr_macro_tri
61  pts_transformed(:,pmic2tmac==k) = repmat(C(:,k),1,length(pts_transformed(pmic2tmac==k)))...
62  + G(:,:,k)*pts_transformed(:,pmic2tmac==k);
63  end
64  pts_transformed = pts_transformed';
65 end