【问题标题】:ellipsoid using matlab椭球使用matlab
【发布时间】:2019-08-02 07:03:57
【问题描述】:

这是一个课堂作业。我写了一些代码,希望有人能帮助我。

这是我的代码

% --- This is optional to verify whether my parametrization is consistent with the
% --- original equation
% syms x y z p t
% ellipsoid=[2*sin(p)*cos(t),4*sin(t)*sin(p),sqrt(2)*cos(p)]
% simplify(subs((x^2/4)+(y^2/16)+(z^2/2),[x,y,z],ellipsoid))
% --- END

t=linspace(-2,2*pi,20);
s=linspace(0,pi/2,20);

[s t]=meshgrid(s,t);

x=2*cos(t).*sin(s); 
y=4.*sin(s).*sin(t); 
z=sqrt(2).*cos(s);

surf(x,y,z); 
grid on;

xlabel('x');ylabel('y');zlabel('z'); axis equal

hold on;
% I think this is how we draw the lower half of the ellipsoid using -sqrt(2)
t=linspace(-2,2*pi,20);
s=linspace(0,pi/2,20);

[s t]=meshgrid(s,t);

x=-2.*cos(t).*sin(s); y=-4.*sin(s).*sin(t); z=-sqrt(2).*cos(s);
surf(x,y,z)
axis equal

第二种方法是使用椭圆注释,这是该问题的第二部分。

[x, y, z] = ellipsoid(0,0,0,2.0,4.0,sqrt(2),20);
surfl(x, y, z)
colormap copper
axis equal

输出图片请点击下方链接(太大)

http://i26.tinypic.com/6ye1j7.jpg 左边是Part a,右边是使用椭球...

你认为它们是一样的吗?

谢谢

【问题讨论】:

    标签: matlab


    【解决方案1】:

    是的,它们几乎相同。

    您可以通过在同一轴上绘制两个椭球来测试它,即在绘制第一个椭球之后,您运行

    [x, y, z] = ellipsoid(0,0,0,2.0,4.0,sqrt(2),20);
    sh = surfl(x, y, z); %# capture the handle, i.e. the unique identifier, of the surface
    
    %# set color to gray, make mostly transparent
    set(sh,'FaceColor',[0.5,0.5,0.5],'FaceAlpha',0.5)
    

    现在您可以旋转绘图(单击带有圆形箭头的按钮,然后拖动绘图),您会看到两个椭圆体非常吻合。如果第二个比第一个大,你会看到两者之间有一个空格;如果第二个比第一个小,你只会看到第一个不透明的。

    【讨论】:

      猜你喜欢
      • 2016-10-27
      • 1970-01-01
      • 2016-09-10
      • 1970-01-01
      • 2012-12-10
      • 2012-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多