常驻嘉宾
- 积分
- 5525
- 威望
- 2875
- 贡献
- 1932
- 兑换币
- 1894
- 注册时间
- 2013-7-23
- 在线时间
- 359 小时
- 毕业学校
- 华中科技大学
|
在MATLAB当中输入type xpquad后出现的源程序,表示看不懂。。久闻此处高手如云,望高手们能予以指点,加以翻译。小弟感激不尽!
if nargin<1,
action='initialize';
end;
if strcmp(action,'initialize'),
figNumber=figure( ...
'Name',getString得到的字符串(message('MATLAB:demos:xpquad:fig_Superquadrics')), ...
'NumberTitle','off', ...
'Visible','off', ...
'Color',0.8*[1 1 1], ...
'BackingStore','off');
colordef(figNumber,'white')
axes( ...
'Units','normalized', ...
'Position',[0.05 0.05 0.70 0.90], ...
'Visible','off');
%===================================
% Information for all buttons(所有按钮的信息)
labelColor=[0.8 0.8 0.8];
top=0.95;
bottom=0.05;
btnWid=0.15;
btnHt=0.10;
right=0.95;
left=right-btnWid;
% Spacing between the button and the next command's label和下一个命令按键标记的间距
spacing=0.02;
%====================================
% The CONSOLE frame 控制台框架
frmBorder=0.02;
yPos=bottom-frmBorder;
frmPos=[left-frmBorder yPos btnWid+2*frmBorder 0.9+2*frmBorder];
h=uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.50 0.50 0.50]);
%====================================
% The first slider 第一个滑块(大概是xpquad右侧的那两个能滑动的第一个)
btnNumber=1;
yPos=top-(btnNumber-1)*(btnHt+spacing);
callbackStr='xpquad(''build'');';
% Generic button information 通用按钮信息
sldPos=[left yPos-2*btnHt btnWid btnHt];
labelPos1=[left yPos-btnHt/2 btnWid btnHt/2];
labelPos2=[left yPos-btnHt btnWid btnHt/2];
sld1Hndl=uicontrol( ...
'Style','slider', ...
'Tag','vertical', ...
'Units','normalized', ...
'Position',sldPos, ...
'Callback',callbackStr);
uicontrol( ...
'Style','text', ...
'String',getString(message('MATLAB:demos:xpquad:uicontrol_Vertical')), ...
'Units','normalized', ...
'Position',labelPos1);
uicontrol( ...
'Style','text', ...
'String',getString(message('MATLAB:demos:xpquad:uicontrol_Roundness')), ...
'Units','normalized', ...
'Position',labelPos2);
%====================================
% The second slider 第二个滑块
btnNumber=3;
yPos=top-(btnNumber-1)*(btnHt+spacing);
callbackStr='xpquad(''build'');';
% Generic button information 通用按钮信息
sldPos=[left yPos-2*btnHt btnWid btnHt];
labelPos1=[left yPos-btnHt/2 btnWid btnHt/2];
labelPos2=[left yPos-btnHt btnWid btnHt/2];
sld2Hndl=uicontrol( ...
'Style','slider', ...
'Tag','horizontal', ...
'Units','normalized', ...
'Position',sldPos, ...
'Callback',callbackStr);
uicontrol( ...
'Style','text', ...
'String',getString(message('MATLAB:demos:xpquad:uicontrol_Horizontal')), ...
'Units','normalized', ...
'Position',labelPos1);
uicontrol( ...
'Style','text', ...
'String',getString(message('MATLAB:demos:xpquad:uicontrol_Roundness')), ...
'Units','normalized', ...
'Position',labelPos2);
%====================================
% The HELP button 帮助按钮
labelStr=getString(message('MATLAB:demos:sharedabelHelp'));
callbackStr=['helpwin ' mfilename];
uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left bottom+btnHt+spacing btnWid btnHt], ...
'String',labelStr, ...
'Callback',callbackStr);
%====================================
% The CLOSE button 关闭按钮
labelStr=getString(message('MATLAB:demos:shared:LabelClose'));
callbackStr='close(gcf)';
uicontrol( ...
'Style','push', ...
'Units','normalized', ...
'Position',[left bottom btnWid btnHt], ...
'String',labelStr, ...
'Callback',callbackStr);
% Uncover the figure 揭示图形
set(figNumber, ...
'Visible','on');
% Make the sliders 16 pixels tall so it looks good on a Mac
set([sld1Hndl sld2Hndl],'Units','pixel')
sld1Pos=get(sld1Hndl,'Position');
sld2Pos=get(sld2Hndl,'Position');
set(sld1Hndl,'Position',[sld1Pos(1) sld1Pos(2)+sld1Pos(4)-16 sld1Pos(3) 16])
set(sld2Hndl,'Position',[sld2Pos(1) sld2Pos(2)+sld2Pos(4)-16 sld2Pos(3) 16])
set([sld1Hndl sld2Hndl],'Units','normalized')
% Draw the initial superquadric
n=5*get(sld1Hndl,'Value');
e=5*get(sld2Hndl,'Value');
[x,y,z]=superquad(n,e,20);
surfHndl=surf(x,y,z);
set(surfHndl,'Tag','surface');
light('Position',[2 -1 10]);
light('Position',[-3 -1 -5]);
lighting phong
axis off;
shading interp;
colormap([0 0 1])
drawnow
elseif strcmp(action,'build'),
%====================================
axHndl=gca;
figNumber=gcf;
sld1Hndl=findobj(gcf,'Tag','horizontal');
sld2Hndl=findobj(gcf,'Tag','vertical');
% Xpquad problem Xpquad
n=5*get(sld1Hndl,'Value');
e=5*get(sld2Hndl,'Value');
[x,y,z]=superquad(n,e,20);
surfaceHndl=findobj(gcf,'Tag','surface');
set(surfaceHndl,'XData',x,'YData',y,'ZData',z)
drawnow
end; % if strcmp(action, ...
|
|