查看单个帖子
旧 2019-12-10, 20:41   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 使用Matlab的椭球

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



这是我的代码

% --- This is optional to verify whether my parametrization is consistent with the % --- original equation % syms xyzpt % 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); [st]=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); [st]=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左边是a部分,右边是椭圆形...

你认为他们是一样的吗?

谢谢



回答:

是的,它们几乎相同。

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

[x, y, z] = ellipsoid(0,0,0,2.0,4.0,sqrt(2),20); sh = surfl(x, y, z); %# capture the handle, ie 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) 现在,您可以旋转绘图(单击带有圆形箭头的按钮,然后拖动绘图),您会看到两个椭圆形重合得很好。如果第二个大于第一个,则您会在两者之间看到一个空格;如果第二个小于第一个,则只会看到第一个不透明的。



更多&回答...
poster 当前离线   回复时引用此帖