?? polygoncutter.m
字號:
function varargout = Polygoncutter(varargin)
% POLYGONCUTTER M-file for Polygoncutter.fig
% POLYGONCUTTER, by itself, creates a new POLYGONCUTTER or raises the existing
% singleton*.
%
% H = POLYGONCUTTER returns the handle to a new POLYGONCUTTER or the handle to
% the existing singleton*.
%
% POLYGONCUTTER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in POLYGONCUTTER.M with the given input arguments.
%
% POLYGONCUTTER('Property','Value',...) creates a new POLYGONCUTTER or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Polygoncutter_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Polygoncutter_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Polygoncutter
% Last Modified by GUIDE v2.5 09-Nov-2007 21:07:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Polygoncutter_OpeningFcn, ...
'gui_OutputFcn', @Polygoncutter_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Polygoncutter is made visible.
function Polygoncutter_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Polygoncutter (see VARARGIN)
zonepoint=str2num(get(handles.zonepointedit,'string'));
x=zonepoint(1);
y=zonepoint(2);
p=str2num(get(handles.polypointedit,'string'));
pp=[p;p(1,:)];
plot(pp(:,1),pp(:,2),'b');hold on;
plot([0 0 x x 0],[0 y y 0 0],'r');hold on;
grid on;
% Choose default command line output for Polygoncutter
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Polygoncutter wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Polygoncutter_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function zonepointedit_Callback(hObject, eventdata, handles)
% hObject handle to zonepointedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of zonepointedit as text
% str2double(get(hObject,'String')) returns contents of zonepointedit as a double
% --- Executes during object creation, after setting all properties.
function zonepointedit_CreateFcn(hObject, eventdata, handles)
% hObject handle to zonepointedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function polypointedit_Callback(hObject, eventdata, handles)
% hObject handle to polypointedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of polypointedit as text
% str2double(get(hObject,'String')) returns contents of polypointedit as a double
% --- Executes during object creation, after setting all properties.
function polypointedit_CreateFcn(hObject, eventdata, handles)
% hObject handle to polypointedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in exe.
function exe_Callback(hObject, eventdata, handles)
% hObject handle to exe (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
format short;
h=findobj('color','b');
delete(h);
h=findobj('color','g');
delete(h);
h=findobj('color','k');
delete(h);
zonepoint=str2num(get(handles.zonepointedit,'string'));
x=zonepoint(1);
y=zonepoint(2);
p=str2num(get(handles.polypointedit,'string'));
[row,len]=size(p);
p=reshape(p,(row*len/2),2);
pp=[p;p(1,:)];
plot(pp(:,1),pp(:,2),'b');hold on;
plot([0 0 x x 0],[0 y y 0 0],'r');hold on;
grid on;
error=0.0001;
[n,dim]=size(p);
j=1;
i=str2num(get(handles.edgechange,'string'));
for k=1:n+1
bit2and=2^(i-1);
temp(k)=getzonecode(zonepoint,pp(k,:)); %get the all the point's code grouped by 1st line
code(k)=bitand(temp(k),bit2and);
end
for k=1:n
judge1=bitand(code(k),code(k+1));
if judge1~=0 %this line is totally unvisible,record no points
else
if code(k)==0&&code(k+1)==0 %this line is totally visible,keep the terminal point
output(j,:)=pp(k+1,:);
j=j+1;
elseif code(k)==0&&code(k+1)~=0 %this line has only p1 in area while p2 outside
sectpoint=intersectp(pp(k,:),pp(k+1,:),zonepoint,error,bit2and,0);
output(j,:)=sectpoint;
j=j+1;
else %this line has only p2 in area while p1 outside
sectpoint=intersectp(pp(k,:),pp(k+1,:),zonepoint,error,bit2and,1);
output(j,:)=sectpoint;
j=j+1;
output(j,:)=pp(k+1,:);
j=j+1;
end
end
end
output=[output;output(1,:)];
[row,len]=size(output);
polypoint=reshape(output,1,row*len);
polystr=num2str(polypoint);
set(handles.polypointedit,'string',polystr);
plot(output(:,1),output(:,2),'k *');hold on;
plot(output(:,1),output(:,2),'g -.');hold on;
axis auto;
i=i+1;
set(handles.edgechange,'string',i);
if i==5
set(handles.exe,'enable','off');
h=findobj('color','b');
delete(h);
end
% --- Executes on button press in credit.
function credit_Callback(hObject, eventdata, handles)
% hObject handle to credit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.zonepointedit,'string','10 10');
set(handles.polypointedit,'string','5 15;15 10;5 -5;-2 5');
delete(get(handles.axes,'children'));
set(handles.exe,'enable','on');
set(handles.edgechange,'string','1');
function edgechange_Callback(hObject, eventdata, handles)
% hObject handle to edgechange (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edgechange as text
% str2double(get(hObject,'String')) returns contents of edgechange as a double
% --- Executes during object creation, after setting all properties.
function edgechange_CreateFcn(hObject, eventdata, handles)
% hObject handle to edgechange (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function saver_Callback(hObject, eventdata, handles)
% hObject handle to saver (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of saver as text
% str2double(get(hObject,'String')) returns contents of saver as a double
% --- Executes during object creation, after setting all properties.
function saver_CreateFcn(hObject, eventdata, handles)
% hObject handle to saver (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -