
我正在嘗試畫出蘆葦葉理。到目前為止,我有下面的程式碼和圖像。問題在於,一個表面通過其前面的表面(通過最前表面)略微凸出。它們應該完全嵌套在前一個內部,就像彎曲的花盆一樣。
settings.outformat="pdf";
settings.prc=false;
settings.render=4;
import graph;
import graph3;
import three;
size(12cm,0);
real rcutoff=.8;
real rinner=1;
real router=2;
currentprojection=orthographic(1,-2,1);
currentlight=(1,-1,0.5);
real f(pair z) {return 1/(1-abs(z)^2);}
// We change variables so that the unit cylinder x^2+y^2<1 gets mapped to the torus.
triple changevariables(triple X)
{
return (
(router+rinner*X.x)*cos(X.z),
(router+rinner*X.x)*sin(X.z),
rinner*X.y
);
}
// g returns the location of a point on a ``paraboloid'' inside the unit cylinder with given angle and radius above the unit disk in the (x,y) plane.
triple g(pair p){
real x=p.x*cos(p.y), y=p.x*sin(p.y);
return (x,y,f((x,y)));
}
triple h(pair p){
return changevariables(g(p));
}
real anglestep=10;
for (int z = 0; z <= 20; ++z) {
draw(
rotate(-anglestep*z,Z)*surface(
h,
(0,0),
(rcutoff,2*pi),Spline
),lightgray+opacity(1)
);
// real zz=f((rcutoff,0));
// triple cent=changevariables((0,0,zz));
// draw(
// rotate(-anglestep,Z)*
// circle(c=cent, r=rcutoff,normal=(-router*sin(zz),router*cos(zz),0)),
// white
// );
}
如果我只用不同的顏色繪製最後兩個表面,也許問題會更清楚:
答案1
這只是由於貝塞爾曲面的表面數值近似所造成的。預設情況下,您有 10 個網格(或 10x10)。根據您的電腦,您可以獨立增加這兩個變數的網格數量。在這裡我測試了最後兩個最終表面
draw(
rotate(-anglestep*z,Z)*surface(
h,
(0,0),
(rcutoff,2*pi),nu=16,nv=10,Spline
),lightgreen+opacity(1)
);
看起來還不錯。