% Testroutine zum Programm % FourPoint, Blatt 9 fprintf(['\n' ... 'Geben Sie zunaechst die Anzahl n der Kontrollpunkte \n' ... 'und dann den Parameter w ein.\n\n' ... 'Klicken Sie dann mit der Maus ein\n'... 'Kontrollpolygon mit n Punkten an.\n'... '\n'... 'Um einen Punkt zu verschieben, klicken Sie auf \n'... 'diesen und bewegen ihn dann mit der Maus.\n'... 'Ein weiterer Klick fixiert den Punkt wieder.\n'... '\n'... 'Ein Klick ausserhalb der Einheitsquadrats beendet das Programm.\n\n']) clear co = inline('[sx(1), sy(1)] + [sx(2), sy(2)].*get(0,''PointerLocation'')','sx','sy'); n = input('Anzahl n = '); if n<=5 error('Das sind zu wenige Kontrollpunkte (warum?)') end w = input('Gewicht w = '); m = n; h1 = pi; h2 = pi; figure(1) clf reset hold on set(gca,'FontSize',17) a = [0 1 0 1]; axis(a) set(1,'Doublebuffer','on') set(1,'Windowbuttondownfcn','stop = 1;') for i=1:n [px(i),py(i)] = ginput(1); z = get(0,'PointerLocation'); X(i) = z(1); Y(i) = z(2); if ishandle(h1) delete(h1); end if ishandle(h2) delete(h2); end h1 = plot(px,py,'LineWidth',3); h2 = plot(px,py,'.','MarkerSize',35); end qx = (px(2)-px(1))/(X(2) - X(1)); qy = (py(2)-py(1))/(Y(2) - Y(1)); sx = [px(1) - qx*X(1), qx]; sy = [py(1) - qy*Y(1), qy]; T = linspace(0,1,m); A = eye(m); for i=1:6 A = FourPoint(A,w); end; A = A'; delete(h1); delete(h2); h1= plot(px,py,'LineWidth',3); h2= plot(px,py,'.','MarkerSize',35); h3= plot(px*A,py*A,'r','LineWidth',3); title(['Gewicht w = ' num2str(w)],'FontSize',15) while 1 waitforbuttonpress %[x,y] = coord(sx,sy); xy = co(sx,sy); x = xy(1); y = xy(2); if x<0 close(1) return end d = abs(px - x) + abs(py - y); [m,i] = min(d); stop = 0; while ~stop %[x,y] = coord(sx,sy); xy = co(sx,sy); x = xy(1); y = xy(2); px(i) = x; py(i) = y; set(h1,'XData',px,'YData',py) set(h2,'XData',px,'YData',py) set(h3,'XData',px*A,'YData',py*A) axis(a) drawnow end end