当我运行以下代码时,程序似乎陷入了无限循环。如果我编写一个没有该abs
函数的函数,程序将正常运行。生成的图类似于下面给出的图片。我的代码有什么问题?
\documentclass[10pt,a4paper]{article}
\usepackage{lmodern}
\usepackage{asypictureB}
\begin{asyheader}
settings.outformat="png";
settings.render=8;
import graph3;
import smoothcontour3;
material surfacepen = material(white, emissivepen = gray(0.2));
\end{asyheader}
%
\begin{document}
%
\begin{asypicture}{name=ellipsoid}
size(5cm,0);
currentprojection = orthographic(12/3,12/4,12/2);
real f(real x, real y, real z) {
return (abs(x))^(0.7) + (abs(y))^(0.7) + (abs(z))^(0.7) - 1;
}
draw(implicitsurface(f, (-1,-1,-1), (1,1,1), overlapedges=true), surfacepen=surfacepen);
xaxis3(Label("$x$",1),-4,4,blue);
yaxis3(Label("$y$",1),-4,4,blue);
zaxis3(Label("$z$",1),-4,4,blue);
\end{asypicture}
\end{document}
答案1
由于幂为 0.7,x=0
或y=0
或中的表面不平滑z=0
。即使您尝试,implicitsurface(f,(0,0,0),(1,1,1))
我也不确定计算是否会停止。使用(0.001,0.001,00.001)
它可以,但表面不完整。
这里有一个不太复杂的表达式:可以用非负坐标给出零件的参数。这是一个可能的解决方案
import graph3;
//import smoothcontour3;
import palette;
material surfacepen = material(white, emissivepen = gray(0.2));
size(5cm,0);
//currentprojection = orthographic(12/3,12/4,12/2);
triple g(pair t){return (t.x, (1-(t.x)^.7)^(1/.7)*t.y,(1-(t.x)^.7-((1-(t.x)^.7)^(1/.7)*t.y)^.7)
);}
surface s0=surface(g,(0,0),(1,1),30,30,Spline);
surface s1=rotate(90,(0,0,0),(0,0,1))*s0;
surface s2=rotate(180,(0,0,0),(0,0,1))*s0;
surface s3=rotate(270,(0,0,0),(0,0,1))*s0;
surface s=surface(s0,s1,s2,s3);
surface sb=reflect((0,0,0),X,Y)*s;
draw(s,surfacepen=surfacepen);
draw(sb,surfacepen=surfacepen);
也许极坐标参数可能会更好。