用matlab进行M文件操作与画图,绘图的,我要程序过程,都是编程题.
发布网友
发布时间:2022-04-26 15:15
我来回答
共1个回答
热心网友
时间:2023-10-11 07:07
x=1;
y=2;
theta=pi/10;
r=0.5;
axis equal
t = linspace(0+theta,2*pi+theta,6);
xr = x+r*cos(t);
yr = y+r*sin(t);
xk = zeros(1,11);
yk = zeros(1,11);
xk(1) = xr(1); yk(1) = yr(1); [xk(2) yk(2)] = CrossPoint([xr(1) yr(1)],[xr(3) yr(3)],[xr(2) yr(2)],[xr(5) yr(5)]);
xk(3) = xr(2); yk(3) = yr(2); [xk(4) yk(4)] = CrossPoint([xr(2) yr(2)],[xr(4) yr(4)],[xr(1) yr(1)],[xr(3) yr(3)]);
xk(5) = xr(3); yk(5) = yr(3); [xk(6) yk(6)] = CrossPoint([xr(2) yr(2)],[xr(4) yr(4)],[xr(3) yr(3)],[xr(5) yr(5)]);
xk(7) = xr(4); yk(7) = yr(4); [xk(8) yk(8)] = CrossPoint([xr(3) yr(3)],[xr(5) yr(5)],[xr(1) yr(1)],[xr(4) yr(4)]);
xk(9) = xr(5); yk(9) = yr(5); [xk(10) yk(10)] = CrossPoint([xr(1) yr(1)],[xr(4) yr(4)],[xr(2) yr(2)],[xr(5) yr(5)]);
xk(11)=xk(1);yk(11)=yk(1);
plot(xk,yk);
%fill(xk,yk,'w')
axis equal
axis off;
需要另写一个函数,计算交叉点
function [x,y]=CrossPoint(p1,p2,p3,p4)
x1 = p1(1); y1 = p1(2);
x2 = p2(1); y2 = p2(2);
x3 = p3(1); y3 = p3(2);
x4 = p4(1); y4 = p4(2);
if x1==x2
x = x1;
k2 = (y4-y3)/(x4-x3);
y = k2*(x-x3)+y3;
elseif x3==x4
x = x3;
k1 = (y2-y1)/(x2-x1);
y = k1*(x-x1)+y1;
else
k1 = (y2-y1)/(x2-x1);
k2 = (y4-y3)/(x4-x3);
sol = [-k1 1;-k2 1]\[y1-k1*x1;y3-k2*x3];
x = sol(1);y = sol(2);
end
end%圆球
syms x y z;
F=x^2+y^2+z^2-16;
nv=jacobian(F,[x y z]);
[x,y,z]=sphere;
surf(4*x,4*y,4*z);
shading interp
%指定某点
x=-1;y=-2;z=sqrt(16-x^2-y^2);
nv=double(subs(nv));
hold on;
quiver3(x,y,z,nv(1),nv(2),nv(3),.5);%法向量
t=-1:.5:1;
[xx,yy]=meshgrid(t+x,t+y);
zz=-(nv(1)*(xx-x)+nv(2)*(yy-y))/nv(3)+z;
mesh(xx,yy,zz);%切平面clear all;
close all;
figure;hold on;
x1=[0 10 10 0 0];
y1=[0 0 0 0 0];
z1=[0 0 10 10 0];
x2=[10 10 10 10 10];
y2=[0 10 10 0 0];
z2=[0 0 10 10 0];
x3=[0 10 10 0 0];
y3=[10 10 10 10 10];
z3=[0 0 10 10 0];
x4=[0 0 0 0 0];
y4=[0 10 10 0 0];
z4=[0 0 10 10 0];
plot3(x1,y1,z1,'Color',[0 0 0]);
plot3(x2,y2,z2,'Color',[0 0 0]);
plot3(x3,y3,z3,'Color',[0 0 0]);
plot3(x4,y4,z4,'Color',[0 0 0]);
% plot3(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,x5,y5,z5,'Color',[0 0 0]);
view(3);
x=0:0.1:10;
z=0.4.*(x-5).^2;
y=zeros(length(x));
hold on;
plot3(x,y,z);
y=10.*ones(length(x));
plot3(x,y,z);
y=0:0.1:10;
z=0.4.*(y-5).^2;
x=zeros(length(x));
plot3(x,y,z);
x=10.*ones(length(x));
plot3(x,y,z);
set(gca,'xtick',[],'xticklabel',[]);
set(gca,'ytick',[],'yticklabel',[]);
set(gca,'ztick',[],'zticklabel',[]);