我正在做一道作业题链接到图片我正在尝试找到我的“冰淇淋”锥形曲线的法向量,该曲线由一部分圆锥和一部分球组成。我需要代码方面的帮助,因为我无法正确绘制法向量,因为 Matlab 给出了错误“警告:矩阵接近奇异值或缩放严重。结果可能不准确。RCOND = 3.710940e-21。”我真的不知道如何解决这个问题。你能帮我找到这个问题的解决方案吗?
PS:下面的代码是针对 Q5 的,它需要 Q4 描述中给出的球体和圆锥体的方程式。
u = linspace(0,2*pi,20); v = linspace(0,sqrt(2),20);
[u,v] = meshgrid(u,v);
%Parameterize the sphere
x = v.*cos(u) + 8;
y = v.*sin(u) + 5;
z = sqrt(4-v.^2)+3;
surf(x,y,z);
%normal vectors to the upper hemisphere
Nxs = v.*cos(u)/2;
Nys = v.*sin(u)/2;
Nzs = sqrt(4-v.^2)/2;
%Parameterize the cone
xc = v.*cos(u) + 8;
yc = v.*sin(u) + 5;
zc = 3 + v; %Subbed what xc and yc were into the zc equation: zc = 3+sqrt((xc-8).^2+(yc-5).^2) to come up with a much more and better simplification
u1 = linspace(0,2*pi,10); v1 = linspace(pi/4,3*pi/4,10);
**%Normal Vectors to the Cone - where the error occurs**
Ncx = -v.*cos(u)/sqrt(2*v.^2+6*v.^1+9);
Ncy = -v.*sin(u)/sqrt(2*v.^2+6*v.^1+9);
Ncz = -(3+v)/sqrt(2*v.^2+6*v.^1+9);
%plotting the graph with normal vectors attached
hold on;
surf(x,y,z);
quiver3(x,y,z,Nxs,Nys,Nzs,0.5,'color','k');
surf(xc,yc,zc);
quiver3(v.*cos(u) + 8,v.*sin(u) + 5,3 + v,Ncx,Ncy,Ncz,'color','k');
xlabel('x'); ylabel('y'); zlabel('z');
hold off;
答案1
只需更改这部分代码:
Ncx = -v.*cos(u)./sqrt(2*v.^2+6*v.^1+9);
Ncy = -v.*sin(u)./sqrt(2*v.^2+6*v.^1+9);
Ncz = -(3+v)./sqrt(2*v.^2+6*v.^1+9);
解释:计算 Ncx..z 分量时,您忘记进行元素除法。如果没有点,Matlab 会粗略地尝试计算-v.*cos(u)*inv(2*v.^2+6*v.^1+9)
,因此会出现“矩阵接近奇异值”错误。