## Asymptote using graph3.asy – fig0090

Category: Asymptote,Examples 3D,graph3.asyPh. Ivaldi @ 11 h 11 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(12cm,0,false);
import graph3;
import contour;
import palette;

texpreamble("\usepackage{icomma}");

real f(pair z) {return z.x*z.y*exp(-z.x);}

currentprojection=orthographic(-2.5,-5,1);

draw(surface(f,(0,0),(5,10),20,Spline),palegray,bp+rgb(0.2,0.5,0.7));

scale(true);

xaxis3(Label("$x$",MidPoint),OutTicks());
yaxis3(Label("$y$",MidPoint),OutTicks(Step=2));
zaxis3(Label("$z=xye^{-x}$",Relative(1),align=2E),Bounds(Min,Max),OutTicks);

real[] datumz={0.5,1,1.5,2,2.5,3,3.5};

Label[] L=sequence(new Label(int i) {
return YZ()*(Label(format("$z=%g$",datumz[i]),
align=2currentprojection.vector()-1.5Z,Relative(1)));
},datumz.length);

pen fontsize=bp+fontsize(10);
draw(L,lift(f,contour(f,(0,0),(5,10),datumz)),



Étiquettes : , , , , ,

## Asymptote using graph3.asy – fig0100

Category: Asymptote,Examples 3D,graph3.asyPh. Ivaldi @ 12 h 11 min

 (Compiled with Asymptote version 1.92svn-r4817)

// From documentation of Asymptote
import graph;
import palette;
import contour;
texpreamble("\usepackage{icomma}");

size(10cm,10cm,IgnoreAspect);

pair a=(0,0);
pair b=(5,10);

real fz(pair z) {
return z.x*z.y*exp(-z.x);
}
real f(real x, real y) {return fz((x,y));}

int N=200;
int Divs=10;
int divs=2;

defaultpen(1bp);
pen Tickpen=black;
pen tickpen=gray+0.5*linewidth(currentpen);
pen[] Palette=BWRainbow();

scale(false);

bounds range=image(f,Automatic,a,b,N,Palette);

xaxis("$x$",BottomTop,LeftTicks(pTick=grey, ptick=invisible, extend=true));
yaxis("$y$",LeftRight,RightTicks(pTick=grey, ptick=invisible, extend=true));

// Major contours
real[] Cvals;
Cvals=sequence(11)/10 * (range.max-range.min) + range.min;
draw(contour(f,a,b,Cvals,N,operator ..),Tickpen);

// Minor contours
real[] cvals;
real[] sumarr=sequence(1,divs-1)/divs * (range.max-range.min)/Divs;
for (int ival=0; ival < Cvals.length-1; ++ival)
cvals.append(Cvals[ival]+sumarr);
draw(contour(f,a,b,cvals,N,operator ..),tickpen);

palette("$f(x,y)=xye^{-x}$",range,point(NW)+(0,1),point(NE)+(0,0.25),Top,Palette,
PaletteTicks(N=Divs,n=divs,Tickpen,tickpen));



Étiquettes : , , , , ,

## Asymptote using graph3.asy – fig0110

Category: Asymptote,Examples 3D,graph3.asyPh. Ivaldi @ 13 h 11 min

 (Compiled with Asymptote version 2.14svn-r5318)

import graph3;
import palette;
import contour;
size(14cm,0);
currentprojection=orthographic(-1,-1.5,0.75);
currentlight=(-1,0,5);

real a=1, b=1;
real f(pair z) { return a*(6+sin(z.x/b)+sin(z.y/b));}
real g(pair z){return f(z)-6a;}

// The axes
limits((0,0,4a),(14,14,8a));
xaxis3(Label("$x$",MidPoint),OutTicks());
yaxis3(Label("$y$",MidPoint),OutTicks(Step=2));
ticklabel relativelabel()
{
return new string(real x) {return (string)(x-6a);};
}
zaxis3(Label("$z$",Relative(1),align=2E),Bounds(Min,Max),OutTicks(relativelabel()));

// The surface
surface s=surface(f,(0,0),(14,14),100,Spline);

// Draw the surface
draw(s,pens);
// Project the surface onto the XY plane.
draw(planeproject(unitsquare3)*s,pens,nolight);

// Draw contour for "datumz"
real[] datumz={-1.5, -1, 0, 1, 1.5};
guide[][] pl=contour(g,(0,0),(14,14),datumz);
for (int i=0; i < pl.length; ++i)
for (int j=0; j < pl[i].length; ++j)
draw(path3(pl[i][j]));

// Draw the contours on the surface
draw(lift(f,pl));

if(!is3D())
shipout(bbox(3mm,Fill(black)));



## Asymptote using graph3.asy – fig0120

Category: Asymptote,Examples 3D,graph3.asyPh. Ivaldi @ 14 h 11 min

 (Compiled with Asymptote version 2.14svn-r5318)

import graph3;
import palette;

real sinc(real x){return x != 0 ? sin(x)/x : 1;}

real f(pair z){
real value = (sinc(pi*z.x)*sinc(pi*z.y))**2;
return value^0.25;
}

currentprojection=orthographic(0,0,1);

size(10cm,0);

surface s=surface(f,(-5,-5),(5,5),100,Spline);

draw(planeproject(unitsquare3)*s,nolight);



Étiquettes : , , , , ,

## Asymptote using graph3.asy – fig0130

Category: Asymptote,Examples 3D,graph3.asyPh. Ivaldi @ 15 h 11 min

 (Compiled with Asymptote version 2.14svn-r5318)

settings.render=0;
import graph3;
import palette;
size(10cm,0);
currentprojection=orthographic(2,-2,2.5);

real f(pair z) {
real u=z.x, v=z.y;
return (u/2+v)/(2+cos(u/2)*sin(v));
}

surface s=surface(f,(0,0),(14,14),150,Spline);

if(!is3D())
shipout(bbox(3mm,Fill(black)));



Étiquettes : , , ,

## Asymptote using graph3.asy – fig0140

Category: Asymptote,Examples 3D,graph3.asyPh. Ivaldi @ 16 h 11 min

 (Compiled with Asymptote version 2.14svn-r5318)

settings.render=0;
import graph3;
import palette;
size(10cm,0);
currentprojection=orthographic(2,-2,2.5);

real f(pair z) {
real u=z.x, v=z.y;
return (u/2+v)/(2+cos(u/2)*sin(v));
}

surface s=surface(f,(0,0),(14,14),50,Spline);

draw(s);

if(!is3D())
shipout(bbox(3mm,Fill(black)));



Étiquettes : , , ,

## Asymptote using graph3.asy – fig0150

Category: Asymptote,Examples 3D,graph3.asyPh. Ivaldi @ 17 h 11 min

 (Compiled with Asymptote version 2.14svn-r5318)

settings.render=0;
import graph3;
size(10cm);

currentprojection=orthographic(4,2,4);

real r(real Theta, real Phi){return 1+0.5*(sin(2*Theta)*sin(2*Phi))^2;}
triple f(pair z) {return r(z.x,z.y)*expi(z.x,z.y);}

pen[] pens(triple[] z)
{
return sequence(new pen(int i) {
real a=abs(z[i]);
return a < 1+1e-3 ? black : interp(blue, red, 2*(a-1));
},z.length);
}

surface s=surface(f,(0,0),(pi,2pi),100,Spline);
// Interpolate the corners, and coloring each patch with one color
// produce some artefacts
draw(s,pens(s.cornermean()));

if(!is3D())
shipout(bbox(3mm,Fill(black)));



Étiquettes : , , , , ,

## Asymptote using graph3.asy – fig0160

Category: Asymptote,Examples 3D,graph3.asyPh. Ivaldi @ 18 h 11 min

 (Compiled with Asymptote version 2.14svn-r5318)

settings.render=0;
import graph3;
size(10cm);

currentprojection=orthographic(4,2,4);

real r(real Theta, real Phi){return 1+0.5*(sin(2*Theta)*sin(2*Phi))^2;}
triple f(pair z) {return r(z.x,z.y)*expi(z.x,z.y);}

pen[][] pens(triple[][] z)
{
pen[][] p=new pen[z.length][];
for(int i=0; i < z.length; ++i) {
triple[] zi=z[i];
p[i]=sequence(new pen(int j) {
real a=abs(zi[j]);
return a < 1+1e-3 ? black : interp(blue, red, 2*(a-1));},
zi.length);
}
return p;
}

surface s=surface(f,(0,0),(pi,2pi),100,Spline);
// Here we interpolate the pens, this looks smoother, with fewer artifacts
draw(s,mean(pens(s.corners())));

if(!is3D())
shipout(bbox(3mm,Fill(black)));



Étiquettes : , , , , ,

## Asymptote using graph3.asy – fig0170

Category: Asymptote,Examples 3D,graph3.asyPh. Ivaldi @ 19 h 11 min

 (Compiled with Asymptote version 2.14svn-r5318)

settings.render=0;
import graph3;
size(10cm);

currentprojection=orthographic(4,2,4);

real r(real Theta, real Phi){return 1+0.5*(sin(2*Theta)*sin(2*Phi))^2;}
triple f(pair z) {return r(z.x,z.y)*expi(z.x,z.y);}

pen[][] pens(triple[][] z)
{
pen[][] p=new pen[z.length][];
for(int i=0; i < z.length; ++i) {
triple[] zi=z[i];
p[i]=sequence(new pen(int j) {
real a=abs(zi[j]);
return a < 1+1e-3 ? black : interp(blue, red, 2*(a-1));},
zi.length);
}
return p;
}

surface s=surface(f,(0,0),(pi,2pi),100,Spline);
// Here we determine the colors of vertexes (vertex shading).
// Since the PRC output format does not support vertex shading of Bezier surfaces, PRC patches
// are shaded with the mean of the four vertex colors.
s.colors(pens(s.corners()));
draw(s);

if(!is3D())
shipout(bbox(3mm,Fill(black)));



Étiquettes : , , , , ,

## Asymptote using graph3.asy – fig0180

Category: Asymptote,Examples 3D,graph3.asyPh. Ivaldi @ 20 h 11 min

 The spherical harmonics are the angular portion of the solution to Laplace's equation in spherical coordinates where azimuthal symmetry is not present. The spherical harmonics are defined by: where and is the Legendre polynomial. Source (Compiled with Asymptote version 2.14svn-r5318)

import palette;
import math;
import graph3;

typedef real fct(real);
typedef pair zfct2(real,real);
typedef real fct2(real,real);

real binomial(real n, real k)
{
return gamma(n+1)/(gamma(n-k+1)*gamma(k+1));
}

real factorial(real n) {
return gamma(n+1);
}

real[] pdiff(real[] p)
{ // p(x)=p[0]+p[1]x+...p[n]x^n
// retourne la dérivée de p
real[] dif;
for (int i : p.keys) {
if(i != 0) dif.push(i*p[i]);
}
return dif;
}

real[] pdiff(real[] p, int n)
{ // p(x)=p[0]+p[1]x+...p[n]x^n
// dérivée n-ième de p
real[] dif={0};
if(n >= p.length) return dif;
dif=p;
for (int i=0; i < n; ++i)
dif=pdiff(dif);
return dif;
}

fct operator *(real y, fct f)
{
return new real(real x){return y*f(x);};
}

zfct2 operator +(zfct2 f, zfct2 g)
{// Défini f+g
return new pair(real t, real p){return f(t,p)+g(t,p);};
}

zfct2 operator -(zfct2 f, zfct2 g)
{// Défini f-g
return new pair(real t, real p){return f(t,p)-g(t,p);};
}

zfct2 operator /(zfct2 f, real x)
{// Défini f/x
return new pair(real t, real p){return f(t,p)/x;};
}

zfct2 operator *(real x,zfct2 f)
{// Défini x*f
return new pair(real t, real p){return x*f(t,p);};
}

fct fct(real[] p)
{ // convertit le tableau des coefs du poly p en fonction polynôme
return new real(real x){
real y=0;
for (int i : p.keys) {
y += p[i]*x^i;
}
return y;
};
}

real C(int l, int m)
{
if(m < 0) return 1/C(l,-m);
real OC=1;
int d=l-m, s=l+m;
for (int i=d+1; i <=s ; ++i) OC *= i;
return 1/OC;
}

int csphase=-1;
fct P(int l, int m)
{ // Polynôme de Legendre associé
// http://mathworld.wolfram.com/LegendrePolynomial.html
if(m < 0) return (-1)^(-m)*C(l,-m)*P(l,-m);
real[] xl2;
for (int k=0; k <= l; ++k) {
xl2.push((-1)^(l-k)*binomial(l,k));
if(k != l) xl2.push(0);
}
fct dxl2=fct(pdiff(xl2,l+m));
return new real(real x){
return (csphase)^m/(2^l*factorial(l))*(1-x^2)^(m/2)*dxl2(x);
};
}

zfct2 Y(int l, int m)
{// http://fr.wikipedia.org/wiki/Harmonique_sph%C3%A9rique#Expression_des_harmoniques_sph.C3.A9riques_normalis.C3.A9es
return new pair(real theta, real phi) {
return sqrt((2*l+1)*C(l,m)/(4*pi))*P(l,m)(cos(theta))*expi(m*phi);
};
}

real xyabs(triple z){return abs(xypart(z));}

size(16cm);
currentprojection=orthographic(0,1,1);

zfct2 Ylm;

triple F(pair z)
{
//   real r=0.75+dot(0.25*I,Ylm(z.x,z.y));
//   return r*expi(z.x,z.y);
real r=abs(Ylm(z.x,z.y))^2;
return r*expi(z.x,z.y);
}

int nb=4;
for (int l=0; l < nb; ++l) {
for (int m=0; m <= l; ++m) {
Ylm=Y(l,m);

surface s=surface(F,(0,0),(pi,2pi),60);
s.colors(palette(s.map(xyabs),Rainbow()));

triple v=(-m,0,-l);
draw(shift(v)*s);
label("$Y_"+ string(l) + "^" + string(m) + "$:",shift(X/3)*v);
}
}



## Asymptote using three.asy – fig0020

Category: Asymptote,Examples 3D,three.asyPh. Ivaldi @ 15 h 50 min

 (Compiled with Asymptote version 2.14svn-r5318)

import three;
import palette;

size(12cm);
currentprojection=orthographic(1,1,1.5);
currentlight=(1,0,1);

triple P00=-X-Y+0.5*Z, P03=-X+Y, P33=X+Y, P30=X-Y;

triple[][] P={
{P00,P00+(-0.5,0.5,-1),P03+(0,-0.5,1),P03},
{P00+(0.5,-0.5,-1),(-0.5,-0.5,0.5),(-0.5,0.5,-1.5),P03+(0.5,0,1)},
{P30+(-0.5,0,1),(0.5,-0.5,-1.5),(0.5,0.5,1),P33+(-0.5,0,1)},
{P30,P30+(0,0.5,1),P33+(0,-0.5,1),P33}
};

surface s=surface(patch(P));
// s.colors(palette(s.map(zpart),Rainbow()));

draw(s);
draw(sequence(new path3(int i){
return s.s[i].external();},s.s.length), bp+orange);

if(!is3D())
shipout(bbox(Fill(lightgrey)));



Étiquettes : , , , , ,

## Asymptote using three.asy – fig0030

Category: Asymptote,Examples 3D,three.asyPh. Ivaldi @ 16 h 50 min

 (Compiled with Asymptote version 2.14svn-r5318)

import three;

size(10cm);
currentlight=(0,0,1);

surface sf=surface(patch(P=new triple[][] {
{(0,0,0),(1,0,0),(1,0,0),(2,0,0)},
{(0,1,0),(1,0,1),(1,0,1),(2,1,0)},
{(0,1,0),(1,0,-1),(1,0,-1),(2,1,0)},
{(0,2,0),(1,2,0),(1,2,0),(2,2,0)}
}));

draw(sf,surfacepen=yellow);
draw(sf.s[0].vequals(0.5),squarecap+2bp+blue,currentlight);
draw(sf.s[0].uequals(0.5),squarecap+2bp+red,currentlight);



Étiquettes : , , , , ,

## Asymptote using solids.asy – fig0080

Category: Asymptote,Examples 3D,solids.asyPh. Ivaldi @ 9 h 56 min

 (Compiled with Asymptote version 2.14svn-r5318)

import solids;
import palette;
size(14cm,0);
currentlight=light(gray(0.4),specularfactor=3,viewport=false,
(-0.5,-0.25,0.45),
(0.5,-0.5,0.5),(0.5,0.5,0.75));

nslice=4*nslice;
surface s=surface(sphere(O,1));
draw(s,lightgrey);

path3 pl=plane((1,0,0),(0,1,0),(0,0,-1));
surface pls=shift(3,3,-1e-3)*scale(-6,-6,1)*surface(pl);
draw(pls,0.7*red);

real dist(triple z){return abs(z-Z);}

for (int i=0; i < currentlight.position.length; ++i) {
nolight);
}



Étiquettes : , , , , , ,

## Asymptote using tube.asy – fig0210

Category: Asymptote,Examples 3D,tube.asyPh. Ivaldi @ 15 h 11 min

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;
import palette;

size(12cm,0);
currentprojection=perspective(1,1,1);

int e=1;
real x(real t) {return cos(t)+2*cos(2t);}
real y(real t) {return sin(t)-2*sin(2t);}
real z(real t) {return 2*e*sin(3t);}

path3 p=scale3(2)*graph(x,y,z,0,2pi,50,operator ..)&cycle;

pen[] pens=Rainbow(15);
pens.push(black);
for (int i=pens.length-2; i >= 0 ; --i)
pens.push(pens[i]);

path sec=subpath(Circle(0,1.5,2*pens.length),0,pens.length);
coloredpath colorsec=coloredpath(sec, pens,colortype=coloredNodes);
draw(tube(p,colorsec));



Étiquettes : , , ,

## Official Asymptote example – Gouraudcontour

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;
import palette;
import contour;

size(200);

int n=100;

real[] x=new real[n];
real[] y=new real[n];
real[] f=new real[n];

real F(real a, real b) {return a^2+b^2;}

real r() {return 1.1*(rand()/randMax*2-1);}

for(int i=0; i < n; ++i) {
x[i]=r();
y[i]=r();
f[i]=F(x[i],y[i]);
}

pen Tickpen=black;
pen tickpen=gray+0.5*linewidth(currentpen);
pen[] Palette=BWRainbow();

bounds range=image(x,y,f,Range(0,2),Palette);
draw(contour(pairs(x,y),f,new real[]{0.25,0.5,1},operator ..));

palette("$f(x,y)$",range,point(NW)+(0,0.5),point(NE)+(0,0.8),Top,Palette,
PaletteTicks(Tickpen,tickpen));



Étiquettes : , , ,

## Official Asymptote example – RiemannSurface

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;
import palette;

size(200,300,keepAspect=false);
//settings.nothin=true;

currentprojection=orthographic(10,10,30);
currentlight=(10,10,5);
triple f(pair t) {return (exp(t.x)*cos(t.y),exp(t.x)*sin(t.y),t.y);}

surface s=surface(f,(-4,-2pi),(0,4pi),8,16,Spline);
s.colors(palette(s.map(zpart),Rainbow()));
draw(s,render(merge=true));



Étiquettes : , , , ,

## Official Asymptote example – RiemannSurfaceRoot

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

// Riemann surface of z^{1/n}
import graph3;
import palette;

int n=3;

size(200,300,keepAspect=false);

currentprojection=orthographic(10,10,30);
currentlight=(10,10,5);
triple f(pair t) {return (t.x*cos(t.y),t.x*sin(t.y),t.x^(1/n)*sin(t.y/n));}

surface s=surface(f,(0,0),(1,2pi*n),8,16,Spline);
s.colors(palette(s.map(zpart),Rainbow()));

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



Étiquettes : , , ,

## Official Asymptote example – cheese

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;
import palette;
import contour3;
size(400);

real f(real x, real y, real z) {
return cos(x)*sin(y)+cos(y)*sin(z)+cos(z)*sin(x);
}

surface sf=surface(contour3(f,(-2pi,-2pi,-2pi),(2pi,2pi,2pi),12));
draw(sf,nolight,render(merge=true));



Étiquettes : , , , , ,

## Official Asymptote example – colors

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

int i=0;
int j=0;

bool components=false;

pen p;

void col(bool fill=false ... string[] s) {
for(int n=0; n < s.length; ++n) {
j -= 10;
string s=s[n];
eval("p="+s+";",true);
if(components) {
real[] a=colors(p);
for(int i=0; i < a.length; ++i)
s += " "+(string) a[i];
}
if(fill) label(s,(i+10,j),E,p,Fill(gray));
else label(s,(i+10,j),E,p);
fill(box((i,j-5),(i+10,j+5)),p);
}
}

col("palered");
col("lightred");
col("mediumred");
col("red");
col("heavyred");
col("brown");
col("darkbrown");
j -= 10;

col("palegreen");
col("lightgreen");
col("mediumgreen");
col("green");
col("heavygreen");
col("deepgreen");
col("darkgreen");
j -= 10;

col("paleblue");
col("lightblue");
col("mediumblue");
col("blue");
col("heavyblue");
col("deepblue");
col("darkblue");
j -= 10;

i += 150;
j=0;

col("palecyan");
col("lightcyan");
col("mediumcyan");
col("cyan");
col("heavycyan");
col("deepcyan");
col("darkcyan");
j -= 10;

col("pink");
col("lightmagenta");
col("mediummagenta");
col("magenta");
col("heavymagenta");
col("deepmagenta");
col("darkmagenta");
j -= 10;

col("paleyellow");
col("lightyellow");
col("mediumyellow");
col("yellow");
col("lightolive");
col("olive");
col("darkolive");
j -= 10;

col("palegray");
col("lightgray");
col("mediumgray");
col("gray");
col("heavygray");
col("deepgray");
col("darkgray");
j -= 10;

i += 150;
j=0;

col("black");
col("white",fill=true);
j -= 10;

col("orange");
col("fuchsia");
j -= 10;
col("chartreuse");
col("springgreen");
j -= 10;
col("purple");
col("royalblue");
j -= 10;

col("Cyan");
col("Magenta");
col("Yellow");
col("Black");

j -= 10;

col("cmyk(red)");
col("cmyk(blue)");
col("cmyk(green)");



Étiquettes :

## Official Asymptote example – condor

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

// Peter Luschny's Condor function
// http://www.luschny.de/math/asy/ElCondorYElGamma.html

import palette;
import graph3;

size(300,300,IgnoreAspect);
currentprojection=orthographic(0,-1,0,center=true);
currentlight=White;
real K=7;

triple condor(pair t)
{
real y=t.y;
real x=t.x*y;
real e=gamma(y+1);
real ymx=y-x;
real ypx=y+x;
real a=gamma((ymx+1)/2);
real b=gamma((ymx+2)/2);
real c=gamma((ypx+1)/2);
real d=gamma((ypx+2)/2);
real A=cos(pi*ymx);
real B=cos(pi*ypx);
return (x,y,log(e)+log(a)*((A-1)/2)+log(b)*((-A-1)/2)+log(c)*((B-1)/2)+
log(d)*((-B-1)/2));
}

surface s=surface(condor,(-1,0),(1,K),16,Spline);
s.colors(palette(s.map(zpart),Rainbow()));

draw(s,render(compression=Low,merge=true));



Étiquettes : , , , ,

## Official Asymptote example – elevation

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;
import grid3;
import palette;

currentprojection=orthographic(0.8,1,1);

size(400,300,IgnoreAspect);

defaultrender.merge=true;

real f(pair z) {return cos(2*pi*z.x)*sin(2*pi*z.y);}

surface s=surface(f,(-1/2,-1/2),(1/2,1/2),50,Spline);

draw(s,mean(palette(s.map(zpart),Rainbow())),black);

grid3(XYZgrid);



Étiquettes : , , , ,

## Official Asymptote example – extrudedcontour

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import contour;
import palette;
import graph3;

defaultrender.merge=true;

currentprojection=orthographic(25,10,10);
size(0,12cm);
real a=3;
real b=4;
real f(pair z) {return (z.x+z.y)/(2+cos(z.x)*sin(z.y));}
guide[][] g=contour(f,(-10,-10),(10,10),new real[]{8},150);

render render=render(merge=true);
for(guide p:g[0]){
draw(extrude(p,8Z),palered,render);
draw(path3(p),red+2pt,render);
}

draw(lift(f,g),red+2pt,render);

surface s=surface(f,(0,0),(10,10),20,Spline);
s.colors(palette(s.map(zpart),Rainbow()+opacity(0.5)));
draw(s,render);
axes3("$x$","$y$","$z$",Arrow3);



Étiquettes : , , , ,

## Official Asymptote example – filesurface

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

 (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();
*/

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



Étiquettes : , , , , ,

## Official Asymptote example – fillcontour

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;
import palette;
import contour;

size(12cm,IgnoreAspect);

pair a=(pi/2,0);
pair b=(3pi/2,2pi);

real f(real x, real y) {return cos(x)*sin(y);}

int N=100;
int Divs=10;

defaultpen(1bp);

bounds range=bounds(-1,1);

real[] Cvals=uniform(range.min,range.max,Divs);
guide[][] g=contour(f,a,b,Cvals,N,operator --);

pen[] Palette=quantize(Rainbow(),Divs);

pen[][] interior=interior(g,extend(Palette,grey,black));
fill(g,interior);
draw(g);

palette("$f(x,y)$",range,point(SE)+(0.5,0),point(NE)+(1,0),Right,Palette,
PaletteTicks("$%+#0.1f$",N=Divs));



Étiquettes : , , , , ,

## Official Asymptote example – fin

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import three;
import palette;

int N = 26;
real[] C = array(N,0);
real[][] A = new real[N][N];
for(int i = 0; i < N; ++i)
for(int j = 0; j < N; ++j)
A[i][j] = 0;

real Tb = 100; // deg C
real h = 240; // 240 W/m^2 K
real k = 240; // W/m K
real Tinf = 20; // deg C
real L = 12; // cm
real t = 2; // cm

real delta = 0.01; // 1 cm = 0.01 m

// (1,2)-(2,2)-(3,2)-...-(13,2)
//   |     |     |          |
// (1,1)-(2,1)-(3,1)-...-(13,1)
//
//        |
//       \ /
//        V
//
// 13-14-15-...-24-25
//  |  |  | ...  |  |
//  0- 1- 2-...-11-12

// but, note zero-based array indexing, so counting starts at 0
int indexof(int m, int n)
{
return 13(n-1)+m-1;
}

int i = 0;

// fixed temperature bottom left
A[i][indexof(1,1)] = 1; C[i] = Tb;
++i;
// fixed temperature middle left
A[i][indexof(1,2)] = 1; C[i] = Tb;
++i;

// interior nodes
for(int m = 2; m<13; ++m)
{
A[i][indexof(m,2)] = -4;
A[i][indexof(m-1,2)] = A[i][indexof(m+1,2)] = 1;
A[i][indexof(m,1)] = 2;
C[i] = 0;
++i;
}

// convective bottom side nodes
for(int m = 2; m<13; ++m)
{
A[i][indexof(m,1)] = -(2+h*delta/k);
A[i][indexof(m-1,1)] = A[i][indexof(m+1,1)] = 0.5;
A[i][indexof(m,2)] = 1;
C[i] = -h*delta*Tinf/k;
++i;
}

// convective bottom right corner node
A[i][indexof(13,2)] = A[i][indexof(12,1)] = 0.5;
A[i][indexof(13,1)] = -(1+h*delta/k);
C[i] = -h*delta*Tinf/k;
++i;

// convective middle right side node
A[i][indexof(13,2)] = -(2+h*delta/k);
A[i][indexof(13,1)] = 1;
A[i][indexof(12,2)] = 1;
C[i] = -h*delta*Tinf/k;
++i;

real[] T = solve(A,C);

real[][] T = {T[0:13],T[13:26],T[0:13]};
T = transpose(T);

size3(15cm);
real w = 10;
real h = 5;
currentprojection = orthographic(2*(L,h,w),Y);
draw((L,t,0)--(L,0,0)--(L,0,w)--(0,0,w)--(0,-h,w));
draw((0,t,w)--(0,t+h,w)--(0,t+h,0)--(0,t,0));
draw((L,0,w)--(L,t,w)--(0,t,w)--(0,t,0)--(L,t,0)--(L,t,w));

real wo2 = 0.5*w;
draw((0,0,wo2)--(0,t,wo2)--(L,t,wo2)--(L,0,wo2)--cycle);

// centre points
surface square = surface(shift(-0.5,-0.5,wo2)*unitsquare3);
surface bottomsquare = surface(shift(-0.5,-0.5,wo2)*scale(1,0.5,1)*unitsquare3);
surface topsquare = surface(shift(-0.5,0,wo2)*scale(1,0.5,1)*unitsquare3);
surface leftsquare = surface(shift(-0.5,-0.5,wo2)*scale(0.5,1,1)*unitsquare3);
surface rightsquare = surface(shift(0,-0.5,wo2)*scale(0.5,1,1)*unitsquare3);
surface NEcorner = surface(shift(0,0,wo2)*scale(0.5,0.5,1)*unitsquare3);
surface SEcorner = surface(shift(0,-0.5,wo2)*scale(0.5,0.5,1)*unitsquare3);
surface SWcorner = surface(shift(-0.5,-0.5,wo2)*scale(0.5,0.5,1)*unitsquare3);
surface NWcorner = surface(shift(-0.5,0,wo2)*scale(0.5,0.5,1)*unitsquare3);

material lookupColour(int m,int n)
{
int index = round(Palette.length*(T[m-1][n-1]-60)/(100-60));
if(index >= Palette.length) index = Palette.length-1;
return emissive(Palette[index]);
}

draw(shift(0,1,0)*rightsquare,lookupColour(1,2));
for(int i = 2; i < 13; ++i)
{
draw(shift(i-1,1,0)*square,lookupColour(i,2));
}
draw(shift(12,1,0)*leftsquare,lookupColour(13,2));

draw(shift(0,2,0)*SEcorner,lookupColour(1,3));
draw(shift(0,0,0)*NEcorner,lookupColour(1,1));
for(int i = 2; i < 13; ++i)
{
draw(shift(i-1,0,0)*topsquare,lookupColour(i,1));
draw(shift(i-1,2,0)*bottomsquare,lookupColour(i,3));
}
draw(shift(12,2,0)*SWcorner,lookupColour(13,3));
draw(shift(12,0,0)*NWcorner,lookupColour(13,1));

// annotations
draw("$x$",(0,-h/2,w)--(L/4,-h/2,w),Y,Arrow3(HookHead2(normal=Z)),BeginBar3(Y));
draw("$y$",(0,0,1.05*w)--(0,2t,1.05*w),Z,Arrow3(HookHead2(normal=X)),
BeginBar3(Z));
draw("$z$",(L,-h/2,0)--(L,-h/2,w/4),Y,Arrow3(HookHead2(normal=X)),BeginBar3(Y));

draw("$L$",(0,-h/4,w)--(L,-h/4,w),-Y,Arrows3(HookHead2(normal=Z)),
Bars3(Y),PenMargins2);
draw("$w$",(L,-h/4,0)--(L,-h/4,w),-Y,Arrows3(HookHead2(normal=X)),
Bars3(Y),PenMargins2);
draw("$t$",(1.05*L,0,0)--(1.05*L,t,0),-2Z,Arrows3(HookHead2(normal=Z)),
Bars3(X),PenMargins2);

label(ZY()*"$T_b$",(0,t+h/2,wo2));

label("$h$,$T_\infty$",(L/2,t+h/2,0),Y);
path3 air = (L/2,t+h/3,w/3.5)--(1.5*L/2,t+2*h/3,w/8);



Étiquettes : , , ,

## Official Asymptote example – gamma3

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;
import palette;

size(12cm,IgnoreAspect);
currentprojection=orthographic(1,-2,1);

real X=4.5;
real M=abs(gamma((X,0)));

pair Gamma(pair z)
{
return (z.x > 0 || z != floor(z.x)) ? gamma(z) : M;
}

real f(pair z) {return min(abs(Gamma(z)),M);}

surface s=surface(f,(-2.1,-2),(X,2),70,Spline);

real Arg(triple v)
{
return degrees(Gamma((v.x,v.y)),warn=false);
}

s.colors(palette(s.map(Arg),Wheel()));
draw(s,render(compression=Low,merge=true));

real xmin=point((-1,-1,-1)).x;
real xmax=point((1,1,1)).x;
draw((xmin,0,0)--(xmax,0,0),dashed);

xaxis3("$\mathop{\rm Re} z$",Bounds,InTicks);
yaxis3("$\mathop{\rm Im} z$",Bounds,InTicks(beginlabel=false));
zaxis3("$|\Gamma(z)|$",Bounds,InTicks);



Étiquettes : , , , ,

## Official Asymptote example – image

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

size(12cm,12cm);

import graph;
import palette;

int n=256;
real ninv=2pi/n;
real[][] v=new real[n][n];

for(int i=0; i < n; ++i)
for(int j=0; j < n; ++j)
v[i][j]=sin(i*ninv)*cos(j*ninv);

pen[] Palette=BWRainbow();

picture bar;

bounds range=image(v,(0,0),(1,1),Palette);
palette(bar,"$A$",range,(0,0),(0.5cm,8cm),Right,Palette,
PaletteTicks("$%+#.1f$"));



Étiquettes : , ,

## Official Asymptote example – imagecontour

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;
import palette;
import contour;

size(10cm,10cm,IgnoreAspect);

pair a=(0,0);
pair b=(2pi,2pi);

real f(real x, real y) {return cos(x)*sin(y);}

int N=200;
int Divs=10;
int divs=2;

defaultpen(1bp);
pen Tickpen=black;
pen tickpen=gray+0.5*linewidth(currentpen);
pen[] Palette=BWRainbow();

bounds range=image(f,Automatic,a,b,N,Palette);

// Major contours

real[] Cvals=uniform(range.min,range.max,Divs);
draw(contour(f,a,b,Cvals,N,operator --),Tickpen);

// Minor contours
real[] cvals;
for(int i=0; i < Cvals.length-1; ++i)
cvals.append(uniform(Cvals[i],Cvals[i+1],divs)[1:divs]);
draw(contour(f,a,b,cvals,N,operator --),tickpen);

xaxis("$x$",BottomTop,LeftTicks,above=true);
yaxis("$y$",LeftRight,RightTicks,above=true);

palette("$f(x,y)$",range,point(NW)+(0,0.5),point(NE)+(0,1),Top,Palette,
PaletteTicks(N=Divs,n=divs,Tickpen,tickpen));



Étiquettes : , , , ,

## Official Asymptote example – imagehistogram

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import stats;
import graph;
import palette;
import contour;

size(20cm);

scale(false);

pair[] data=new pair[50000];
for(int i=0; i < data.length; ++i)
data[i]=Gaussrandpair();

// Histogram limits and number of bins
pair datamin=(-0.15,-0.15);
pair datamax=(0.15,0.15);
int Nx=30;
int Ny=30;

int[][] bins=frequency(data,datamin,datamax,Nx,Ny);

real[] values=new real[Nx*Ny];
pair[] points=new pair[Nx*Ny];
int k=0;
real dx=(datamax.x-datamin.x)/Nx;
real dy=(datamax.y-datamin.y)/Ny;
for(int i=0; i < Nx; ++i) {
for(int j=0; j < Ny; ++j) {
values[k]=bins[i][j];
points[k]=(datamin.x+(i+0.5)*dx,datamin.y+(j+0.5)*dy);
++k;
}
}

// Create a color palette
pen[] InvGrayscale(int NColors=256) {
real ninv=1.0/(NColors-1.0);
return sequence(new pen(int i) {return gray(1-17*i*ninv);},NColors);
}

// Draw the histogram, with axes
bounds range=image(points,values,Range(0,40),InvGrayscale());
draw(contour(points,values,new real[] {1,2,3,4,8,12,16,20,24,28,32,36,40},
operator--),blue);
xaxis("$x$",BottomTop,LeftTicks,above=true);
yaxis("$y$",LeftRight,RightTicks,above=true);



Étiquettes : , , , ,

## Official Asymptote example – laserlattice

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;
import palette;

int n=256;
pen[] Palette=BWRainbow();

real w(real w0, real z0, real z) {return w0*sqrt(1+(z/z0)^2);}

real pot(real lambda, real w0, real r, real z)
{
real z0=pi*w0^2/lambda, kappa=2pi/lambda;
return exp(-2*(r/w(w0,z0,z))^2)*cos(kappa*z)^2;
}

picture make_field(real lambda, real w0)
{
real[][] v=new real[n][n];
for(int i=0; i < n; ++i)
for(int j=0; j < n; ++j)
v[i][j]=pot(lambda,w0,i-n/2,abs(j-n/2));

picture p=new picture;
size(p,250,250,IgnoreAspect);
real xm=-n/lambda, ym=-n/(2*w0), xx=n/lambda, yx=n/(2*w0);
image(p,v,(xm,ym),(xx,yx),Palette);
xlimits(p,xm,xx);
ylimits(p,ym,yx);
xaxis(p,"{\Large $z/\frac{\lambda}{2}$}",BottomTop,LeftTicks);
yaxis(p,"{\Large $r/w_0$}",LeftRight,RightTicks);
label(p,format("{\LARGE $w_0/\lambda=%.2f$}",w0/lambda),point(p,NW),5N);

return p;
}

picture p=make_field(160,80);
picture q=make_field(80,80);
picture r=make_field(16,80);
picture s=make_field(2,80);

real margin=1cm;



Étiquettes : , , , , ,

## Official Asymptote example – logimage

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;
import palette;

size(10cm,10cm,IgnoreAspect);

real f(real x, real y) {
return 0.9*pow10(2*sin(x/5+2*y^0.25)) + 0.1*(1+cos(10*log(y)));
}

scale(Linear,Log,Log);

pen[] Palette=BWRainbow();

bounds range=image(f,Automatic,(0,1),(100,100),nx=200,Palette);

xaxis("$x$",BottomTop,LeftTicks,above=true);
yaxis("$y$",LeftRight,RightTicks,above=true);

palette("$f(x,y)$",range,(0,200),(100,250),Top,Palette,
PaletteTicks(ptick=linewidth(0.5*linewidth())));



Étiquettes : , , ,

## Official Asymptote example – p-orbital

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;
import palette;
size(200);
currentprojection=orthographic(6,8,2);
viewportmargin=(1cm,0);

real c0=0.1;

real f(real r) {return r*(1-r/6)*exp(-r/3);}

triple f(pair t) {
real r=t.x;
real phi=t.y;
real f=f(r);
real s=max(min(c0/f,1),-1);
real R=r*sqrt(1-s^2);
return (R*cos(phi),R*sin(phi),r*s);
}

bool cond(pair t) {return f(t.x) != 0;}

real R=abs((20,20,20));
surface s=surface(f,(0,0),(R,2pi),100,8,Spline,cond);

render render=render(compression=Low,merge=true);
draw(s,render);
draw(zscale3(-1)*s);

axes3("$x$","$y$","$z$",Arrow3);



Étiquettes : , , , ,

## Official Asymptote example – parametricelevation

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;
import palette;
size(200);

currentprojection=orthographic(4,2,4);

triple f(pair z) {return expi(z.x,z.y);}

surface s=surface(f,(0,0),(pi,2pi),10,Spline);
draw(s,mean(palette(s.map(zpart),BWRainbow())),black,nolight,render(merge=true));



Étiquettes : , , ,

## Official Asymptote example – partialsurface

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;
import palette;

size(0,300);
currentprojection=perspective(3,-2,2);

real V(real r) {return r^4-r^2;}
real V(pair pos) {return V(abs(pos));}

real R=1/sqrt(2);
real z=-0.2;

bool active(pair pos) {return abs(pos) < R;}
bool above(pair pos) {return V(pos) >= z;}

pair a=(-1.5,-1);
pair b=(0.5,1);
real f=1.2;

draw(plane(f*(b.x-a.x,0,z),(0,f*(b.y-a.y),z),(a.x,a.y,z)),
lightgrey+opacity(0.5));

surface s=surface(V,a,b,40,Spline,active);
draw(s,mean(palette(s.map(new real(triple v) {
return above((v.x,v.y)) ? 1 : 0;}),
new pen[] {lightblue,lightgreen})),black);

xaxis3(Label("$\phi^\dagger\phi$",1),red,Arrow3);
zaxis3(Label("$V(\phi^\dagger\phi)$",1),0,0.3,red,Arrow3);



Étiquettes : , , ,

## Official Asymptote example – penimage

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

size(200);

import palette;

int n=256;
real ninv=2pi/n;
pen[][] v=new pen[n][n];

for(int i=0; i < n; ++i)
for(int j=0; j < n; ++j)
v[i][j]=rgb(0.5*(1+sin(i*ninv)),0.5*(1+cos(j*ninv)),0);

image(v,(0,0),(1,1));



Étiquettes : ,

## Official Asymptote example – projectelevation

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;
import grid3;
import palette;

currentprojection=orthographic(0.8,1,2);
size(400,300,IgnoreAspect);

real f(pair z) {return cos(2*pi*z.x)*sin(2*pi*z.y);}

surface s=surface(f,(-1/2,-1/2),(1/2,1/2),50,Spline);

surface S=planeproject(unitsquare3)*s;
S.colors(palette(s.map(zpart),Rainbow()));
draw(S,nolight);
draw(s,lightgray+opacity(0.7));

grid3(XYZgrid);



## Official Asymptote example – projectrevolution

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import solids;
import palette;

currentprojection=orthographic(20,0,3);

size(400,300,IgnoreAspect);

revolution r=revolution(new real(real x) {return sin(x)*exp(-x/2);},
0,2pi,operator ..,Z);
surface s=surface(r);

surface S=planeproject(shift(-Z)*unitsquare3)*s;
S.colors(palette(s.map(zpart),Rainbow()));

render render=render(compression=Low,merge=true);
draw(S,render);
draw(s,lightgray,render);



Étiquettes : , , , , , , ,

## Official Asymptote example – smoothelevation

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;
import grid3;
import palette;

currentlight=Viewport;

if(settings.render <= 0) settings.prc=false;

currentprojection=orthographic(1,2,13);

size(400,300,IgnoreAspect);

real f(pair z) {return cos(2*pi*z.x)*sin(2*pi*z.y);}

surface s=surface(f,(-1/2,-1/2),(1/2,1/2),20,Spline);
s.colors(palette(s.map(zpart),Rainbow()));

draw(s);

scale(true);

xaxis3(Label("$x$",0.5),Bounds,InTicks);
yaxis3(Label("$y$",0.5),Bounds,InTicks);
zaxis3(Label("$z$",0.5),Bounds,InTicks(beginlabel=false));

grid3(XYZgrid);



Étiquettes : , , , ,

## Official Asymptote example – sphericalharmonic

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;
import palette;
size(200);

currentprojection=orthographic(4,2,4);
currentlight=Viewport;

real r(real theta, real phi) {return 1+0.5*(sin(2*theta)*sin(2*phi))^2;}

triple f(pair z) {return r(z.x,z.y)*expi(z.x,z.y);}

surface s=surface(f,(0,0),(pi,2pi),50,Spline);
draw(s,render(compression=Low,merge=true));



Étiquettes : , , ,

## Official Asymptote example – spiral3

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;
import palette;

size3(10cm);

currentprojection=orthographic(5,4,2);
viewportmargin=(2cm,0);

real r(real t) {return 3exp(-0.1*t);}
real x(real t) {return r(t)*cos(t);}
real y(real t) {return r(t)*sin(t);}
real z(real t) {return t;}

path3 p=graph(x,y,z,0,6*pi,50,operator ..);

tube T=tube(p,2);
surface s=T.s;
s.colors(palette(s.map(zpart),BWRainbow()));
draw(s,render(merge=true));
draw(T.center,thin());



Étiquettes : , , , , ,

## Official Asymptote example – trefoilknot

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import tube;
import graph3;
import palette;
currentlight=White;

size(0,8cm);
currentprojection=perspective(1,1,1,up=-Y);

int e=1;
real x(real t) {return cos(t)+2*cos(2t);}
real y(real t) {return sin(t)-2*sin(2t);}
real z(real t) {return 2*e*sin(3t);}

path3 p=scale3(2)*graph(x,y,z,0,2pi,50,operator ..)&cycle;

pens.push(yellow);
for (int i=pens.length-2; i >= 0 ; --i)
pens.push(pens[i]);

path sec=scale(0.25)*texpath("$\pi$")[0];
coloredpath colorsec=coloredpath(sec, pens,colortype=coloredNodes);
draw(tube(p,colorsec),render(merge=true));



Étiquettes : , , , ,

## Official Asymptote example – twistedtubes

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

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;
import palette;

size(300,300,keepAspect=true);

real w=0.4;

real f(triple t) {return sin(t.x);}
triple f1(pair t) {return (cos(t.x)-2cos(w*t.y),sin(t.x)-2sin(w*t.y),t.y);}
triple f2(pair t) {return (cos(t.x)+2cos(w*t.y),sin(t.x)+2sin(w*t.y),t.y);}
triple f3(pair t) {return (cos(t.x)+2sin(w*t.y),sin(t.x)-2cos(w*t.y),t.y);}
triple f4(pair t) {return (cos(t.x)-2sin(w*t.y),sin(t.x)+2cos(w*t.y),t.y);}

surface s1=surface(f1,(0,0),(2pi,10),8,8,Spline);
surface s2=surface(f2,(0,0),(2pi,10),8,8,Spline);
surface s3=surface(f3,(0,0),(2pi,10),8,8,Spline);
surface s4=surface(f4,(0,0),(2pi,10),8,8,Spline);

pen[] Rainbow=Rainbow();
s1.colors(palette(s1.map(f),Rainbow));
s2.colors(palette(s2.map(f),Rainbow));
s3.colors(palette(s3.map(f),Rainbow));
s4.colors(palette(s4.map(f),Rainbow));

defaultrender.merge=true;

draw(s1);
draw(s2);
draw(s3);
draw(s4);



Étiquettes : , ,