用MATLAB作出柱面x^2+y^2=4 和柱面x^2+z^2=4 相交的图形.

1个回答

  • 程序如下:

    t=0:pi/20:2*pi;

    x=sin(t)*2;

    y=cos(t)*2;

    z=linspace(-5,5,length(t));

    X=meshgrid(x);Y=meshgrid(y);Z=[meshgrid(z)]';

    mesh(X,Y,Z)%第一个圆柱面

    xlabel('x')

    ylabel('y')

    zlabel('z')

    hold on

    x1=sin(t)*2;

    z1=cos(t)*2;

    y1=linspace(-5,5,length(t));

    X1=meshgrid(x1);Y1=[meshgrid(y1)]';Z1=meshgrid(z1);

    mesh(X1,Y1,Z1)%第二个圆柱面

    plot3(sin(t)*2,cos(t)*2,cos(t)*2,'k-*','LineWidth',2)%交线1

    hold on

    plot3(-sin(t)*2,-cos(t)*2,cos(t)*2,'k-*','LineWidth',2)%交线2

    title('柱面x^2+y^2=4 和柱面x^2+z^2=4 相交的图形')

    结果: