You are on page 1of 1

Chapter 8: Base modules 158

To construct contours for an array of values f specified at irregularly positioned points z,


use the routine
guide[][] contour(pair[] z, real[] f, real[] c, interpolate join=operator --);
The contours themselves can be drawn with one of the routines
void draw(picture pic=currentpicture, Label[] L=new Label[],
guide[][] g, pen p=currentpen);

void draw(picture pic=currentpicture, Label[] L=new Label[],


guide[][] g, pen[] p);
The following simple example draws the contour at value 1 for the function z = x2 + y 2 ,
which is a unit circle:
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}));

The next example draws and labels multiple contours for the function z = x2 − y 2 with
the resolution 100 x 100, using a dashed pen for negative contours and a solid pen for
positive (and zero) contours:
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);

You might also like