## Asymptote using graph.asy – fig0250

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 2 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(10cm,0);
import contour;
import graph;

xlimits( -3, 3);
ylimits( -3, 3);
yaxis( "\$y\$" , Ticks());
xaxis( "\$x\$", Ticks());

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

draw(contour(f,(-3,-3),(3,3),new real[] {1}));

```

Étiquettes : , , , ,

## Asymptote using graph.asy – fig0260

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 3 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(10cm,0);
import contour;
import stats;
import graph;

xlimits( -5, 5);
ylimits( -4, 5);
yaxis( "\$y\$" , Ticks(Label(currentpen+fontsize(8),align=E)));
xaxis( "\$x\$", Ticks(Label(currentpen+fontsize(8))));

real f(real x, real y) {return x^2-x-y^2+3y-6;}

int min=-5,
max=5,
n=max-min+1;

real[] value=sequence(min,max);

pen[] p=sequence(new pen(int i) {
return (value[i] >= 0 ? solid : dashed) +
(value[i] >= 0 ? (value[i]/max)*red : (value[i]/min)*blue) +
fontsize(4);
},n);

Label[] Labels=sequence(new Label(int i) {
return Label(value[i] != 0 ? (string) value[i] : "",Relative(unitrand()),(0,0),
UnFill(1bp));
},n);

draw(Labels,contour(f,(-5,-5),(5,5),value),p);

```

Étiquettes : , , , , ,

## Asymptote using graph3.asy – fig0080

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
// Adapted from the documentation of Asymptote.
import graph3;
import contour;
texpreamble("\usepackage{icomma}");

size3(12cm,12cm,8cm,IgnoreAspect);

real sinc(pair z) {
real r=2pi*abs(z);
return r != 0 ? sin(r)/r : 1;
}

limits((-2,-2,-0.2),(2,2,1.2));
currentprojection=orthographic(1,-2,0.5);

xaxis3(rotate(90,X)*"\$x\$",
Bounds(Min,Min),
OutTicks(rotate(90,X)*Label, endlabel=false));

yaxis3("\$y\$", Bounds(Max,Min), InTicks(Label));
zaxis3("\$z\$", Bounds(Min,Min), OutTicks());

draw(lift(sinc,contour(sinc,(-2,-2),(2,2),new real[] {0})), bp+0.8*red);
draw(surface(sinc,(-2,-2),(2,2),nx=100, Spline), lightgray);

draw(scale3(2*sqrt(2))*unitdisk, paleyellow+opacity(0.25), nolight);
draw(scale3(2*sqrt(2))*unitcircle3, 0.8*red);

```

Étiquettes : , , , ,

## 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)),
palette(datumz,Gradient(fontsize+red,fontsize+black)));

```

É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);

pen[] pens=mean(palette(s.map(zpart),Gradient(yellow,red)));

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

```

## 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 – 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));
sf.colors(palette(sf.map(abs),Gradient(red,yellow)));
draw(sf,nolight,render(merge=true));

```

É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 – 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 – 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 – impact

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 */

// Contributed by Philippe Ivaldi.
// http://www.piprime.fr/

import graph3 ;
import contour;
size (6cm,0);
currentprojection=orthographic(1,1,1) ;

real rc=1, hc=2, c=rc/hc;
draw(shift(hc*Z)*scale(rc,rc,-hc)*unitcone,blue);

triple Os=(0.5,0.5,1);
real r=0.5;
draw(shift(Os)*scale3(r)*unitsphere,red);

real a=1+1/c^2;
real b=abs(Os)^2-r^2;

real f(pair z)
{
real x=z.x, y=z.y;
return a*x^2-2*Os.x*x+a*y^2-2*Os.y*y-2*Os.z*sqrt(x^2+y^2)/c+b;
}

real g(pair z){return (sqrt(z.x^2+z.y^2))/c;}

draw(lift(g,contour(f,(-rc,-rc),(rc,rc),new real[]{0})),linewidth(2bp)+yellow);

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

```

Étiquettes : , , , ,

## Official Asymptote example – irregularcontour

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

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

import contour;

size(200);

int n=100;

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

srand(1);

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

pair[] points=new pair[n];
real[] values=new real[n];

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

draw(contour(points,values,new real[]{0.25,0.5,1},operator ..),blue);

```

Étiquettes : ,

## Official Asymptote example – magnetic

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 contour3;

size(200,0);
currentprojection=orthographic((6,8,2),up=Y);

real a(real z) {return (z < 6) ? 1 : exp((abs(z)-6)/4);}
real b(real z) {return 1/a(z);}
real B(real z) {return 1-0.5cos(pi*z/10);}

real f(real x, real y, real z) {return 0.5B(z)*(a(z)*x^2+b(z)*y^2)-1;}

draw(surface(contour3(f,(-2,-2,-10),(2,2,10),10)),blue+opacity(0.75),
render(merge=true));

xaxis3(Label("\$x\$",1),red);
yaxis3(Label("\$y\$",1),red);
zaxis3(Label("\$z\$",1),red);

```

Étiquettes : , , ,

## Official Asymptote example – multicontour

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

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

import contour;

size(200);

real f(real x, real y) {return x^2-y^2;}
int n=10;
real[] c=new real[n];
for(int i=0; i < n; ++i) c[i]=(i-n/2)/n;

pen[] p=sequence(new pen(int i) {
return (c[i] >= 0 ? solid : dashed)+fontsize(6pt);
},c.length);

Label[] Labels=sequence(new Label(int i) {
return Label(c[i] != 0 ? (string) c[i] : "",Relative(unitrand()),(0,0),
UnFill(1bp));
},c.length);

draw(Labels,contour(f,(-1,-1),(1,1),c),p);

```

Étiquettes : , , , ,

## Official Asymptote example – onecontour

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 contour;
size(75);

real f(real a, real b) {return a^2+b^2;}
draw(contour(f,(-1,-1),(1,1),new real[] {1}));

```

Étiquettes : ,

## Official Asymptote example – sinc

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 */

import graph3;
import contour;

currentprojection=orthographic(1,-2,1);
currentlight=White;

size(12cm,0);

real sinc(pair z) {
real r=2pi*abs(z);
return r != 0 ? sin(r)/r : 1;
}

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

draw(lift(sinc,contour(sinc,(-2,-2),(2,2),new real[] {0})),red);
draw(surface(sinc,(-2,-2),(2,2),Spline),lightgray,render);

draw(scale3(2*sqrt(2))*unitdisk,paleyellow+opacity(0.25),nolight,render);
draw(scale3(2*sqrt(2))*unitcircle3,red,render);

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

```

Étiquettes : , , , ,

## Animation with Asymptote – fig0010

Category: Animation,AsymptotePh. Ivaldi @ 8 h 20 min

 (Compiled with Asymptote version 1.43)
Movie flash (swf)
This animation is available in the Syracuse web site.
```
import contour3;
import animate;
// settings.tex="pdflatex";
// settings.outformat="pdf";

size(10cm);
currentprojection=orthographic(15,8,10);
animation A;
A.global=false;

typedef real fct3(real,real,real);
fct3 F(real t)
{
return new real(real x, real y, real z){return x^2+y^2-t*z^2+t-1;};
}

int n=15;
picture pic;
real tmin=0.1, tmax=2;
real step=(tmax-tmin)/n;
draw(box((-5,-5,-5),(5,5,5)));
for (int i=0; i < n; ++i) {
save();
draw(surface(contour3(F(tmin+i*step),(-5,-5,-5),(5,5,5),15)),lightblue);
pic.erase();
add(pic,bbox(5mm,FillDraw(lightyellow)));
A.add(pic);
restore();
}

A.movie();

```

Étiquettes : , , ,