CodeCodeCode

draw

Mar 31st, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.15 KB | None | 0 0
  1. function draw_wire
  2. % Click the left mouse button to define a point
  3. % Drag the mouse to draw a line to the next point and
  4. % left click again
  5. % Right click the mouse to stop drawing
  6.  
  7. figure('WindowButtonDownFcn',@wbdcb)
  8. axis1 = axes('DrawMode','fast');
  9. axis ([1 10 1 10])
  10.    function wbdcb(src,evnt)
  11.       if strcmp(get(src,'SelectionType'),'normal')      
  12.          [x,y,str] = disp_point(axis1);
  13.          hl = line('XData',x,'YData',y,'Marker','.');
  14.          text(x,y,str,'VerticalAlignment','bottom');drawnow
  15.          set(src,'WindowButtonMotionFcn',@wbmcb)
  16.       elseif strcmp(get(src,'SelectionType'),'alt')
  17.          set(src,'WindowButtonMotionFcn','')
  18.          [x,y,str] = disp_point(axis1);
  19.          text(x,y,str,'VerticalAlignment','bottom');drawnow
  20.       end
  21.       function wbmcb(src,evnt)
  22.          [xn,yn,str] = disp_point(axis1);
  23.          xdat = [x,xn];
  24.          ydat = [y,yn];
  25.          set(hl,'XData',xdat,'YData',ydat);
  26.       end  
  27.    end
  28.    function [x,y,str] = disp_point(axis1)
  29.       cp = get(axis1,'CurrentPoint');  
  30.       x = cp(1,1);y = cp(1,2);
  31.       str = ['(',num2str(x,'%0.3g'),', ',num2str(y,'%0.3g'),')'];    
  32.    end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment