📄 bezier_curve_plotter.m
字号:
function varargout = Bezier_Curve_Plotter(varargin)
% BEZIER_CURVE_PLOTTER M-file for Bezier_Curve_Plotter.fig
% BEZIER_CURVE_PLOTTER, by itself, creates a new BEZIER_CURVE_PLOTTER or raises the existing
% singleton*.
%
% H = BEZIER_CURVE_PLOTTER returns the handle to a new BEZIER_CURVE_PLOTTER or the handle to
% the existing singleton*.
%
% BEZIER_CURVE_PLOTTER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BEZIER_CURVE_PLOTTER.M with the given input arguments.
%
% BEZIER_CURVE_PLOTTER('Property','Value',...) creates a new BEZIER_CURVE_PLOTTER or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Bezier_Curve_Plotter_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Bezier_Curve_Plotter_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 Bezier_Curve_Plotter
% Last Modified by GUIDE v2.5 27-Oct-2007 13:29:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Bezier_Curve_Plotter_OpeningFcn, ...
'gui_OutputFcn', @Bezier_Curve_Plotter_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 Bezier_Curve_Plotter is made visible.
function Bezier_Curve_Plotter_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 Bezier_Curve_Plotter (see VARARGIN)
P=[1 1 1;3 5 6;5 5 9;7 2 10]; %control points
pointsize=size(P); %get the points decides the number of bases 4=5-1 and dimension;
length=pointsize(1);
N=20; %plot 20 points
set(handles.choose2d,'value',0);
set(handles.choose3d,'value',1);
set(handles.Bezierfunc,'value',1);
[base,all]=Bezierall(P,N);
plot3(P(:,1),P(:,2),P(:,3),'r o');hold on;
plot3(all(1,:,1),all(1,:,2),all(1,:,3));grid on;
u=str2num(get(handles.inputu,'string')); %the parameter value
value=Beziervalue(P,u);
set(handles.valueout,'string',num2str(value));
% Choose default command line output for Bezier_Curve_Plotter
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Bezier_Curve_Plotter wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Bezier_Curve_Plotter_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;
% --- Executes on button press in choose2d.
function choose2d_Callback(hObject, eventdata, handles)
% hObject handle to choose2d (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of choose2d
set(handles.choose3d,'value',0);
set(handles.choose2d,'value',1);
% --- Executes on button press in choose3d.
function choose3d_Callback(hObject, eventdata, handles)
% hObject handle to choose3d (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of choose3d
set(handles.choose2d,'value',0);
set(handles.choose3d,'value',1);
function pointsedit_Callback(hObject, eventdata, handles)
% hObject handle to pointsedit (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 pointsedit as text
% str2double(get(hObject,'String')) returns contents of pointsedit as a double
% --- Executes during object creation, after setting all properties.
function pointsedit_CreateFcn(hObject, eventdata, handles)
% hObject handle to pointsedit (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 Basefunc.
function Basefunc_Callback(hObject, eventdata, handles)
% hObject handle to Basefunc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.Bezierfunc,'value',0);
set(handles.Basefunc,'value',1);
P=str2num(get(handles.pointsedit,'String')); %#ok<ST2NM>
N=str2num(get(handles.Numedit,'String')); %#ok<ST2NM>
% Hint: get(hObject,'Value') returns toggle state of Basefunc
pointsize=size(P); %get the points decides the number of bases 4=5-1 and dimension;
length=pointsize(1);
[base,all]=Bezierall(P,N);
u=(0:(N-1))./N; %to plot the base functions
for i=1:length
handles.basehandle(i)=subplot(length,1,i); plot(u,base(i,:));grid on; %get the handles
end
% --- Executes on button press in Bezierfunc.
function Bezierfunc_Callback(hObject, eventdata, handles)
% hObject handle to Bezierfunc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of Bezierfunc
set(handles.Basefunc,'value',0);
set(handles.Bezierfunc,'value',1);
P=str2num(get(handles.pointsedit,'String')); %#ok<ST2NM>
N=str2num(get(handles.Numedit,'String')); %#ok<ST2NM>
% Hint: get(hObject,'Value') returns toggle state of Basefunc
%pointsize=size(P); %get the points decides the number of bases 4=5-1 and dimension;
%length=pointsize(1);
[base,all]=Bezierall(P,N);
%pointsize=size(P); %get the points decides the number of bases 4=5-1 and dimension;
%length=pointsize(1);
%clear the base plotting but axis remains!!!!damn!!!
basehandles=get(handles.plotpanel,'children');
len=length(basehandles);
for i=1:len
cla(basehandles(i));
end
%can only delete the objects
delete(get(handles.plotpanel,'children'))
if (get(handles.choose2d,'value')==1)
%delete(get(handles.plotpanel,'children'))
%if delete,might delete the axes1,so the plot might not in plotpanel
plot(P(:,1),P(:,2),'r o');hold on;
%set the plotting in the plotting panel,impotrant!!!or the axis is
%delete,the plotting shall take all the figure
set(gca,'parent',handles.plotpanel);
plot(all(1,:,1),all(1,:,2));grid on;
else
%delete(get(handles.plotpanel,'children'))
plot3(P(:,1),P(:,2),P(:,3),'r o');hold on;
set(gca,'parent',handles.plotpanel);
plot3(all(1,:,1),all(1,:,2),all(1,:,3));grid on;
end
function Numedit_Callback(hObject, eventdata, handles)
% hObject handle to Numedit (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 Numedit as text
% str2double(get(hObject,'String')) returns contents of Numedit as a double
% --- Executes during object creation, after setting all properties.
function Numedit_CreateFcn(hObject, eventdata, handles)
% hObject handle to Numedit (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 inputu_Callback(hObject, eventdata, handles)
% hObject handle to inputu (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 inputu as text
% str2double(get(hObject,'String')) returns contents of inputu as a double
% --- Executes during object creation, after setting all properties.
function inputu_CreateFcn(hObject, eventdata, handles)
% hObject handle to inputu (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 valueout_Callback(hObject, eventdata, handles)
% hObject handle to valueout (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 valueout as text
% str2double(get(hObject,'String')) returns contents of valueout as a double
% --- Executes during object creation, after setting all properties.
function valueout_CreateFcn(hObject, eventdata, handles)
% hObject handle to valueout (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 showvalue.
function showvalue_Callback(hObject, eventdata, handles)
% hObject handle to showvalue (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
u=str2num(get(handles.inputu,'string')); %#ok<ST2NM>
P=str2num(get(handles.pointsedit,'String')); %#ok<ST2NM>
if ((u<=1)&&(u>=0))
value=Beziervalue(P,u);
set(handles.valueout,'string',num2str(value));
if get(handles.choose2d,'value')==1 %choose 2d;
pointhandles=findobj('color','m');
delete(pointhandles);
plot(value(1),value(2),'m *');
else %choose 3d;
pointhandles=findobj('color','m');
delete(pointhandles);
plot3(value(1),value(2),value(3),'m *');
end
else
value='Invalid Parameter';
set(handles.valueout,'string',value);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -