⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example.m

📁 the intersection of cycl in matlab.show the result in figur.
💻 M
📖 第 1 页 / 共 2 页
字号:
function ci_example(arg);
% example of the use function Circles_Intersection
% is in sub-function 'apply_circles_intersection;'
%
% run without arguments
%
%   Vesrion 2.0
%   Author:  Alexander Vakulenko
%   e-mail:  dspt@yandex.ru
%   Last modified: 20050207
         
global hCI; % handle to main window

narg=nargin;
if narg==0,arg=0;end;
if arg==0,
    hobj=findobj('Type','figure','Tag','ci_example');
    if ~isempty(hobj),
        figure(hobj);
    else
        ci_example_create;
    end;
    return;
end;

switch arg
    case 'WindowButtonMotionFcn',
        WindowButtonMotionFcn;
    case 'WindowButtonDownFcn',
        WindowButtonDownFcn;
    case 'WindowButtonUpFcn',
        WindowButtonUpFcn;
    case 'popKT',
        popKT;
    case 'popSel',
        popSel;
    case 'edit',
        edit;
    case 'pbInsert',
        pbInsert;
    case 'pbRemove',
        pbRemove;
    case 'edit',
        edit;
    case 'pbLoad',
        pbLoad;
    case 'pbSave',
        pbSave;
    case 'popRenderer',
        popRenderer;
    case 'chkCalc',
        chkCalc;
    case 'pbCalc',
        pbCalc;
        
end; % end of main program


%-------------------------------------------------------------------
% functions
%-------------------------------------------------------------------

function apply_circles_intersection;
global hCI;
gw=getappdata(hCI,'handles');
v=get(gw.chkCalc,'value');
if v==1,
    G=gw.G; % input circles
    tic;
    % resolving of singulariyies
    if get(gw.chkDispose,'Value')==1,
        MaxRnd=str2num(get(gw.edtRndVal,'String'));
        ng=size(G);
        G(:,1:2)=G(:,1:2)+randn(ng(1),2)*MaxRnd;
    end;
    try,
        c=Circles_Intersection(G);
        set(gw.chkDispose,'BackGroundColor',[0.64705882352941   0.82352941176471   0.82745098039216]);
    catch
        set(gw.chkDispose,'BackGroundColor','r');
        return;
    end;
    gw.tcalc=toc; % calculation time
    try,
        delete(gw.hr);
    end;
    if gw.kt<=c.K, 
        % convertion contours of arcs to poligonal region
        R=arcs2region(c,gw.kt,3);
        % draw region
        gw.hr=reg_patch(R,'c',gw.hAxs);
        setappdata(hCI,'handles',gw);
        area_of_region=c.w(gw.kt).S;
    else
        area_of_region=0;
    end;
    set(gw.txtTCalc,'String',['Last calcul. time : ' num2str(round(gw.tcalc*1000)/1000) ' s']);
    display_area(gw,area_of_region);
end;
%-------------------------------------------------------------------



function ci_example_create;
global hCI;

% create figure
figColor=[0.64705882352941   0.82352941176471   0.82745098039216];
hCI = figure(...
    'Position',[50 50 700 500],...
    'Units','pixels', ...
    'NumberTitle','off', ...
    'Toolbar','figure', ...
    'MenuBar','none', ...
    'pointer','arrow',...
    'Color',figColor,...
    'Name','INTERACTIVE CIRCLES INTERSECTION', ...
    'NumberTitle','off', ...
    'Resize','off', ...
    'Tag','ci_example');

gw.hCI=hCI;

% create axes
WndPos=get(hCI,'Position');
Hxy_wnd=WndPos(4);
Hxy_axs=Hxy_wnd-20-20;
Wxyh=30+Hxy_axs;
saxy=[30 20 Hxy_axs Hxy_axs]; 
gw.hAxs = axes('Parent',hCI, ...
    'Units','pixels', ...
    'NextPlot','add', ...
    'Box','on', ...
    'Layer','top', ...
    'gridlinestyle',':',...
    'FontName','Times New Roman', ...
    'FontSize',8, ...
    'FontWeight','normal', ...
    'Position',saxy, ...
    'Tag','axesXY', ...
    'XGrid','on', ...
    'XLimMode','manual', ...
    'YGrid','on', ...
    'YLimMode','manual', ...
    'XLim',[-100 100], ...
    'YLim',[-100 100] );
ht=text( -100, 100,'Y axis');
set(ht,'Parent',gw.hAxs,'FontUnits','pixels','FontName','Times New Roman','FontSize',16,'HorizontalAlignment','left','VerticalAlignment','top','Units','pixels','Color','c');
ht=text( 100, -100,'X axis');
set(ht,'Parent',gw.hAxs,'FontUnits','pixels','FontName','Times New Roman','FontSize',16,'HorizontalAlignment','right','VerticalAlignment','bottom','Units','pixels','Color','c');

%create initial circles
G=[      15  70  25;...
        -50  40  48;...
         63  45  31;...
         50  20  15;
         15  13  35;...
         48 -50  15;...
         50 -55  25;...
         65 -65  30];
% draw circamferences
Ng=size(G,1);
ang=(0:3:360)*pi/180;
for k=1:Ng,
    hG(k)=line(G(k,1)+G(k,3)*cos(ang),G(k,2)+G(k,3)*sin(ang),'Parent',gw.hAxs,'Color','g','linestyle',':','linewidth',2);
end;
c_sel=1;
set(hG(c_sel),'Color','b');
h_center_sel=line(G(c_sel,1),G(c_sel,2),'Parent',gw.hAxs,'Color','b','linestyle','none','marker','o','markersize',3);
gw.Ng=Ng;
gw.G=G;
gw.hG=hG;
gw.c_sel=c_sel;
gw.h_center_sel=h_center_sel;

% create the custom pointer
gw.pntr=custom_pointer;
gw.action='none';
gw.kt=1; % number of overlappad circles

xpos=saxy(1)+saxy(3)+3;
ypos=saxy(2)+saxy(4)-100;
wdth=WndPos(3)-xpos-3;
strInf=['Select Circle: click non-selected (green) circumference;' char(13) ...
        'Move   Circle: press mouse button on center of selected circle(blue) and move;' char(13) ...
        'Resize Circle: press mouse button on selected circumference(blue) and move mouse;'];
gw.txtInform=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth 100],...
    'style','text','backgroundcolor',figColor,'HorizontalAlignment','left','string',strInf);
ypos=ypos-18;
gw.txtRenderer=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth*0.3 14],...
    'style','text','backgroundcolor',figColor,'foregroundcolor','k','HorizontalAlignment','left',...
    'string','Renderer:');
strpop={'opengl','zbuffer','painters'};

gw.Renderer=2;
gw.popRenderer=uicontrol('Parent',hCI,'units','pixels','position',[xpos+2+wdth*0.3 ypos wdth*0.7-3 16],...
    'style','popupmenu','backgroundcolor',figColor,'foregroundcolor','k','HorizontalAlignment','left',...
    'string',strpop,'FontWeight','normal','CallBack','ci_example(''popRenderer'');','value',gw.Renderer);
set(hCI,'Renderer',strpop{gw.Renderer});

ypos=ypos-25;;
gw.txtKT=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth 16],...
    'style','text','backgroundcolor',figColor,'foregroundcolor',[0 0.4 0.4],'HorizontalAlignment','left',...
    'string',['Number of overlapped circles (>=):'],'FontWeight','bold');

ypos=ypos-20;
strpop=popupmenustring(gw.Ng);
gw.popKT=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth 20],...
    'style','popupmenu','backgroundcolor',figColor,'foregroundcolor',[0 0.4 0.4],'HorizontalAlignment','left',...
    'string',strpop,'FontWeight','bold','CallBack','ci_example(''popKT'');','value',gw.kt);

ypos=ypos-25;
gw.txtArea_1=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth*0.55 18],...
    'style','text','backgroundcolor',figColor,'foregroundcolor',[0 0.4 0.4],'HorizontalAlignment','left',...
    'string','Area of region:','FontWeight','bold','fontsize',8);
gw.txtArea=uicontrol('Parent',hCI,'units','pixels','position',[xpos+wdth*0.55 ypos wdth*0.45 18],...
    'style','text','backgroundcolor',figColor,'foregroundcolor',[0 0.4 0.4],'HorizontalAlignment','center',...
    'string','0','FontWeight','bold','fontsize',8);
ypos=ypos-5;
gw.frmPrgbB=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth 5],...
    'style','frame','backgroundcolor',figColor);
gw.frmPrgb=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth-10 5],...
    'style','frame','backgroundcolor',[0.5 0.7 0.4],'UserData',1000);

ypos=ypos-25;
gw.txtSel=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth 18],...
    'style','text','backgroundcolor',figColor,'foregroundcolor','b','HorizontalAlignment','center',...
    'string','Selected Circle:','FontWeight','bold','fontsize',8);
ypos=ypos-20;
strpop=popupmenustring(gw.Ng);
gw.popSel=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth 20],...
    'style','popupmenu','backgroundcolor',figColor,'foregroundcolor','b','HorizontalAlignment','left',...
    'string',strpop,'FontWeight','bold','CallBack','ci_example(''popSel'');','value',gw.c_sel);
ypos=ypos-18;
gw.txtX=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth/2 16],...
    'style','text','backgroundcolor',figColor,'foregroundcolor','b','HorizontalAlignment','right',...
    'string','X coord:   ','FontWeight','bold','fontsize',8);
gw.edtX=uicontrol('Parent',hCI,'units','pixels','position',[xpos+wdth/2 ypos wdth/2 16],...
    'style','edit','backgroundcolor',figColor,'foregroundcolor','b','HorizontalAlignment','left',...
    'string','123','FontWeight','bold','fontsize',8,'Callback','ci_example(''edit'');');
ypos=ypos-18;
gw.txtY=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth/2 16],...
    'style','text','backgroundcolor',figColor,'foregroundcolor','b','HorizontalAlignment','right',...
    'string','Y coord:   ','FontWeight','bold','fontsize',8);
gw.edtY=uicontrol('Parent',hCI,'units','pixels','position',[xpos+wdth/2 ypos wdth/2 16],...
    'style','edit','backgroundcolor',figColor,'foregroundcolor','b','HorizontalAlignment','left',...
    'string','-234','FontWeight','bold','fontsize',8,'Callback','ci_example(''edit'');');
ypos=ypos-18;
gw.txtR=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth/2 16],...
    'style','text','backgroundcolor',figColor,'foregroundcolor','b','HorizontalAlignment','right',...
    'string','Radius:    ','FontWeight','bold','fontsize',8);
gw.edtR=uicontrol('Parent',hCI,'units','pixels','position',[xpos+wdth/2 ypos wdth/2 16],...
    'style','edit','backgroundcolor',figColor,'foregroundcolor','b','HorizontalAlignment','left',...
    'string','222','FontWeight','bold','fontsize',8,'Callback','ci_example(''edit'');');
ypos=ypos-20;
gw.pbInsert=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth/2 18],...
    'style','pushbutton','backgroundcolor',figColor,'foregroundcolor','k','HorizontalAlignment','right',...
    'string','INSERT','FontWeight','bold','fontsize',8,'Callback','ci_example(''pbInsert'');');
gw.pbRemove=uicontrol('Parent',hCI,'units','pixels','position',[xpos+wdth/2 ypos wdth/2 18],...
    'style','pushbutton','backgroundcolor',figColor,'foregroundcolor','k','HorizontalAlignment','left',...
    'string','REMOVE','FontWeight','bold','fontsize',8,'Callback','ci_example(''pbRemove'');');

ypos=ypos-20;
gw.chkCalc=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth/2 16],'Value',1,...
    'style','checkbox','backgroundcolor',figColor,'foregroundcolor','k','HorizontalAlignment','left',...
    'string','AutoCalc','FontWeight','bold','fontsize',8,'Callback','ci_example(''chkCalc'');');
gw.pbCalc=uicontrol('Parent',hCI,'units','pixels','position',[xpos+wdth/2 ypos wdth/2 18],'Enable','off',...
    'style','pushbutton','backgroundcolor',figColor,'foregroundcolor',[0 0.5 0],'HorizontalAlignment','left',...
    'string','ReCalc','FontWeight','bold','fontsize',8,'Callback','ci_example(''pbCalc'');');
ypos=ypos-18;
gw.chkDispose=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth 16],'Value',1,...
    'style','checkbox','backgroundcolor',figColor,'foregroundcolor',[0.2392    0.4941    0.5608],'HorizontalAlignment','left',...
    'string','Dispose singular case','FontWeight','bold','fontsize',8);
ypos=ypos-18;
gw.txtRndVal=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth*0.6 16],'Value',0,...
    'style','text','backgroundcolor',figColor,'foregroundcolor',[0.2392    0.4941    0.5608],'HorizontalAlignment','left',...
    'string','Max Random Value:','FontWeight','bold','fontsize',8);
gw.edtRndVal=uicontrol('Parent',hCI,'units','pixels','position',[xpos+wdth*0.6 ypos wdth*0.4 16],'Value',0,...
    'style','edit','backgroundcolor',figColor,'foregroundcolor',[0.2392    0.4941    0.5608],'HorizontalAlignment','left',...
    'string','1e-9','FontWeight','bold','fontsize',8);

ypos=ypos-30;
gw.pbSave=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth/2 18],...
    'style','pushbutton','backgroundcolor',figColor,'foregroundcolor',[0 0.5 0],'HorizontalAlignment','right',...
    'string','SAVE...','FontWeight','bold','fontsize',8,'Callback','ci_example(''pbSave'');');
gw.pbLoad=uicontrol('Parent',hCI,'units','pixels','position',[xpos+wdth/2 ypos wdth/2 18],...
    'style','pushbutton','backgroundcolor',figColor,'foregroundcolor',[0 0.5 0],'HorizontalAlignment','left',...
    'string','LOAD...','FontWeight','bold','fontsize',8,'Callback','ci_example(''pbLoad'');');

ypos=ypos-30;
gw.txtTCalc=uicontrol('Parent',hCI,'units','pixels','position',[xpos ypos wdth 16],...
    'style','text','backgroundcolor',figColor,'foregroundcolor','k','HorizontalAlignment','left',...
    'string','Last Calcul. time :  0  s','FontWeight','bold','fontsize',8);
gw.tcalc=0;


setappdata(hCI,'handles',gw);
SelectCircle(c_sel,gw);


apply_circles_intersection;

drawnow;

% set mouse events
set(hCI,'WindowButtonMotionFcn','ci_example(''WindowButtonMotionFcn'');');
set(hCI,'WindowButtonDownFcn','ci_example(''WindowButtonDownFcn'');');
set(hCI,'WindowButtonUpFcn','ci_example(''WindowButtonUpFcn'');');




function pntr=custom_pointer;
x=[0.5 6 6 10 10 15.5 10 10 6 6 0.5];
y=[8 15.5 10 10 15.5 8 0.5 6 6 0.5 8];
dx=diff(x);
dy=diff(y);
v=sqrt(dx.*dx+dy.*dy);
n=ceil(v./1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -