Official Asymptote example – BezierSurface

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 8 h 57 min

Figure 0012
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import three;

string viewpoint="
COO=-684.0787963867188 206.90650939941406 218.13809204101562
C2C=0.8244762420654297 -0.563306450843811 0.0540805421769619
ROO=1009.7407942621448
ROLL=17.39344555165265
";

// viewpoint=getstring("viewpoint",viewpoint);
currentprojection=perspective(viewpoint);

triple[][][] P={
  {
    {(-1.6,0,1.875),(-2.3,0,1.875),(-2.7,0,1.875),(-2.7,0,1.65),},
    {(-1.6,-0.3,1.875),(-2.3,-0.3,1.875),(-2.7,-0.3,1.875),(-2.7,-0.3,1.65),},
    {(-1.5,-0.3,2.1),(-2.5,-0.3,2.1),(-3,-0.3,2.1),(-3,-0.3,1.65),},
    {(-1.5,0,2.1),(-2.5,0,2.1),(-3,0,2.1),(-3,0,1.65),}
  },{
    {(-2.7,0,1.65),(-2.7,0,1.425),(-2.5,0,0.975),(-2,0,0.75),},
    {(-2.7,-0.3,1.65),(-2.7,-0.3,1.425),(-2.5,-0.3,0.975),(-2,-0.3,0.75),},
    {(-3,-0.3,1.65),(-3,-0.3,1.2),(-2.65,-0.3,0.7275),(-1.9,-0.3,0.45),},
    {(-3,0,1.65),(-3,0,1.2),(-2.65,0,0.7275),(-1.9,0,0.45),}
  },{
    {(-2.7,0,1.65),(-2.7,0,1.875),(-2.3,0,1.875),(-1.6,0,1.875),},
    {(-2.7,0.3,1.65),(-2.7,0.3,1.875),(-2.3,0.3,1.875),(-1.6,0.3,1.875),},
    {(-3,0.3,1.65),(-3,0.3,2.1),(-2.5,0.3,2.1),(-1.5,0.3,2.1),},
    {(-3,0,1.65),(-3,0,2.1),(-2.5,0,2.1),(-1.5,0,2.1),}
  },{
    {(-2,0,0.75),(-2.5,0,0.975),(-2.7,0,1.425),(-2.7,0,1.65),},
    {(-2,0.3,0.75),(-2.5,0.3,0.975),(-2.7,0.3,1.425),(-2.7,0.3,1.65),},
    {(-1.9,0.3,0.45),(-2.65,0.3,0.7275),(-3,0.3,1.2),(-3,0.3,1.65),},
    {(-1.9,0,0.45),(-2.65,0,0.7275),(-3,0,1.2),(-3,0,1.65),}
  }
};

picture pic;
size(pic,15cm);
size3(pic,10cm);
draw(pic,surface(P),blue);

add(embed("label",pic),(0,0),N);
label(cameralink("label"),(0,0),10S,fontsize(24pt));

Étiquettes : , , ,


Official Asymptote example – Klein

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 19 h 57 min

Figure 0105
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

size(469pt);

viewportmargin=0;

currentprojection=perspective(
camera=(25.0851928432063,-30.3337528952473,19.3728775115443),
up=Z,
target=(-0.590622314050054,0.692357205025578,-0.627122488455679),
zoom=1,
autoadjust=false);

triple f(pair t) {
  real u=t.x;
  real v=t.y;
  real r=2-cos(u);
  real x=3*cos(u)*(1+sin(u))+r*cos(v)*(u < pi ? cos(u) : -1);
  real y=8*sin(u)+(u < pi ? r*sin(u)*cos(v) : 0);
  real z=r*sin(v);
  return (x,y,z);
}

surface s=surface(f,(0,0),(2pi,2pi),8,8,Spline);
draw(s,lightolive+white,"bottle",render(merge=true));

string lo="$\displaystyle u\in[0,\pi]: \cases{x=3\cos u(1+\sin u)+(2-\cos u)\cos u\cos v,\cr
y=8\sin u+(2-\cos u)\sin u\cos v,\cr
z=(2-\cos u)\sin v.\cr}$";

string hi="$\displaystyle u\in[\pi,2\pi]:\\\cases{x=3\cos u(1+\sin u)-(2-\cos u)\cos v,\cr
y=8\sin u,\cr
z=(2-\cos u)\sin v.\cr}$";

real h=0.0125;

begingroup3("parametrization");
draw(surface(xscale(-0.38)*yscale(-0.18)*lo,s,0,1.7,h,bottom=false),
     "[0,pi]");
draw(surface(xscale(0.26)*yscale(0.1)*rotate(90)*hi,s,4.9,1.4,h,bottom=false),
     "[pi,2pi]");
endgroup3();

begingroup3("boundary");
draw(s.uequals(0),blue+dashed);
draw(s.uequals(pi),blue+dashed);
endgroup3();

add(new void(frame f, transform3 t, picture pic, projection P) {
    draw(f,invert(box(min(f,P),max(f,P)),P),"frame");
  });

Étiquettes : , , , , ,


Official Asymptote example – filesurface

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 4 h 57 min

Figure 0065
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import palette;

size3(200,IgnoreAspect);

file in=input("filesurface.dat").line();
real[] x=in;
real[] y=in;

real[][] f=in.dimension(0,0);

triple f(pair t) {
  int i=round(t.x);
  int j=round(t.y);
  return (x[i],y[j],f[i][j]);
}

surface s=surface(f,(0,0),(x.length-1,y.length-1),x.length-1,y.length-1);
real[] level=uniform(min(f)*(1-sqrtEpsilon),max(f)*(1+sqrtEpsilon),4);

s.colors(palette(s.map(new real(triple v) {return find(level >= v.z);}),
                 Rainbow())); 

draw(s,meshpen=thick(),render(merge=true));

triple m=currentpicture.userMin();
triple M=currentpicture.userMax();
triple target=0.5*(m+M);

xaxis3("$x$",Bounds,InTicks);
yaxis3("$y$",Bounds,InTicks(Step=1,step=0.1));
zaxis3("$z$",Bounds,InTicks);

/*
picture palette;
size3(palette,1cm);
draw(palette,unitcube,red);
frame F=palette.fit3();
add(F,(M.x,m.y,m.z));
*/

currentprojection=perspective(camera=target+realmult(dir(68,225),M-m),
                              target=target);



Étiquettes : , , , , ,