# Fill a triangle in space using asymptote

I am trying to draw a triangle in space, given its three vertices, using asymptote.

A minimal example is

``````import grid3;
import graph3;

size(12cm,0);

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

triple p0=(0,0,0);
triple p1=(0,1,1);
triple p2=(1,1,1);

grid3(new grid3routines [] {XYXgrid(0)},
pGrid=new pen[] {0.5blue},
pgrid=new pen[] {0.5blue});

draw(p0--p1--p2--cycle);
``````

This yields the boundary of the polygon. However, I fail to fill the triangle. I assume I could parameterize it and plot it as a parameterized surface, but this didn't work for me as well. I tried to use the following

``````triple f(pair t) {return((1-t.x)*((1-t.y)*p0+t.y*p1)+t.x*p2);}
surface s=surface(f,(0,1),(0,1),10,10,Spline);
s.colors(palette(s.map(zpart),Rainbow()));
draw(s,render(merge=true));
``````

instead of the last `draw` in the previous snippet. This attempt yields an empty page.

How can I fill (and draw its boundary?) a triangle in space using `asymptote`?

To fill the triangle replace

``````draw(p0--p1--p2--cycle);
``````

by

``````draw(surface(p0--p1--p2--cycle),yellow);
draw(p0--p1--p2--cycle);
``````

That's it.

• yes, that's it, that's what I am looking for! thank @Alex! Dec 13 '20 at 2:18