发布网友 发布时间:2022-04-23 11:23
共1个回答
热心网友 时间:2023-11-03 07:23
function figureEx
f0=figure('KeyPressFcn',@printfig);
function printfig(~,evnt)
if evnt.Character == '1'
circleDrawExample; % 白
elseif evnt.Key == '2'
clf; %% ba
elseif evnt.Key == 'q'
exit; %% 白
else
clf;
end
end
end
function circleDrawExample()
% circleDraw函数应用举例
x0 =5;y0=5;R = 4;
[x,y]=circleDraw(5,5,4);
ylim([0,10]);
n=10; %每隔360/n度,画出相应的直线,标出相应的角度
alpha1 = 0:2*pi/n:(2*n-2)*pi/n;
x1=x0+R*cos(alpha1);
y1=y0+R*sin(alpha1);
for i=1:n
d = 360*(i-1)/n;
line([x0,x1(i)],[y0,y1(i)],'LineStyle',':','Color','r','Marker','.');
hold on
text(x1(i),y1(i),strcat('\theta=',num2str(d),'\circ'));
pause(0.01)
end
end
function [x,y]=circleDraw(x0,y0,R,theta)
% 输入:圆心坐标(x0,y0),半径R,theta是圆弧起点和终点
% 输出:圆弧图像
% 举例:circleDraw(2,2,5,[0 pi/2]);
if nargin==3
theta = [0 2*pi];
end
alpha=theta(1):pi/50:theta(2); %角度[0,2*pi]
x=x0+R*cos(alpha);
y=y0+R*sin(alpha);
plot(x,y,'-','LineWidth',2)
axis equal
end