## Asymptote using three.asy – fig0010

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
/* One may view this animated example */
import three;

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));
draw(s,15,15,yellow,meshpen=grey);
draw(sequence(new path3(int i){
return s.s[i].external();},s.s.length), bp+red);

dot("P[0][0]",P[0][0], align=N, black);
dot("P[0][3]",P[0][3], black);
dot("P[3][3]",P[3][3], align=S, black);
dot("P[3][0]",P[3][0], align=W, black);

draw(Label("P[0][1]",align=SW,EndPoint),P[0][0]--P[0][1], Arrow3);
draw(Label("P[1][0]",align=SE,EndPoint),P[0][0]--P[1][0], Arrow3);

draw(Label("P[0][2]",align=E,EndPoint),P[0][3]--P[0][2], Arrow3);
draw(Label("P[1][3]",EndPoint),P[0][3]--P[1][3], Arrow3);

draw(Label("P[2][3]",EndPoint),P[3][3]--P[2][3], Arrow3);
draw(Label("P[3][2]",EndPoint),P[3][3]--P[3][2], Arrow3);

draw(Label("P[3][1]",EndPoint),P[3][0]--P[3][1], Arrow3);
draw(Label("P[2][0]", align=W,EndPoint),P[3][0]--P[2][0], Arrow3);

dot("P[1][1]",P[1][1], align=S);
dot("P[1][2]",P[1][2], align=E);
dot("P[2][2]",P[2][2], align=N);
dot("P[2][1]",P[2][1], align=W);

for (int i=0; i < s.s.length; ++i)
dot(s.s[i].internal(), bp+red);

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

```

Étiquettes : , , , ,

## 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 three.asy – fig0090

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

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

currentprojection=obliqueX;

triple v1=(4,0,0),
v2=(0,6,0),
p0=(-2,-3,0);
path3 pl1=plane(v1,v2,p0);

path ph=transform(v1,v2,p0,currentprojection)*((0,-2){W}..(0,2){W}..cycle);
filldraw(project(pl1)^^ph,evenodd+lightgrey);

```

Étiquettes : , , , , ,

## Official Asymptote example – join3

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;

size(200);

currentprojection=orthographic(500,-500,500);

triple[] z=new triple[10];

z[0]=(0,100,0); z[1]=(50,0,0); z[2]=(180,0,0);

for(int n=3; n <= 9; ++n)
z[n]=z[n-3]+(200,0,0);

path3 p=z[0]..z[1]---z[2]::{Y}z[3]
&z[3]..z[4]--z[5]::{Y}z[6]
&z[6]::z[7]---z[8]..{Y}z[9];

draw(p,grey+linewidth(4mm),currentlight);

xaxis3(Label(XY()*"\$x\$",align=-3Y),red,above=true);
yaxis3(Label(XY()*"\$y\$",align=-3X),red,above=true);

```

Étiquettes :

## Official Asymptote example – pathintersectsurface

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

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

size(500);
import graph3;

currentprojection=perspective(-5,-4,2);

path3 g=randompath3(10);

draw(g,red+thin());

triple[][] P={
{(0,0,0),(1,0,0),(1,0,0),(2,0,0)},
{(0,4/3,0),(2/3,4/3,2),(4/3,4/3,2),(2,4/3,0)},
{(0,2/3,0),(2/3,2/3,0),(4/3,2/3,0),(2,2/3,0)},
{(0,2,0),(2/3,2,0),(4/3,2,0),(2,2,0)}};

surface s=surface(patch(P));
s.append(unitplane);

draw(s,lightgray+opacity(0.9));
dot(intersectionpoints(g,s),blue);

```

Étiquettes : , , ,

## Official Asymptote example – randompath3

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

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

import three;

size(300);
draw(randompath3(100),red,currentlight);

```

Étiquettes : ,

## Official Asymptote example – saddle

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

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

import three;

size(100,0);
path3 g=(1,0,0)..(0,1,1)..(-1,0,0)..(0,-1,1)..cycle;
draw(g);
draw(((-1,-1,0)--(1,-1,0)--(1,1,0)--(-1,1,0)--cycle));
dot(g,red);

```

Étiquettes : , , ,

## Official Asymptote example – unitcircle3

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

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

import three;

size(100);

path3 g=(1,0,0)..(0,1,0)..(-1,0,0)..(0,-1,0)..cycle;
draw(g);
draw(O--Z,red+dashed,Arrow3);
draw(((-1,-1,0)--(1,-1,0)--(1,1,0)--(-1,1,0)--cycle));
dot(g,red);

```

Étiquettes : , ,

## Animation with Asymptote – fig0080

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

 (Compiled with Asymptote version 1.86svn-r4626)
This animation is available in the Syracuse web site.
```
import graph3;
import animation;
import solids;

settings.render=0;
animation A;
A.global=false;

int nbpts=500;
real q=2/5;
real pas=5*2*pi/nbpts;
int angle=3;
real R=3;

unitsize(1cm);

real x(real t){return R*cos(q*t)*cos(t);}
real y(real t){return R*cos(q*t)*sin(t);}
real z(real t){return R*sin(q*t);}

triple[] P;
real t=-pi;
for (int i=0; i<nbpts; ++i) {
t+=pas;
P.push((x(t),y(t),z(t)));
}

currentprojection=orthographic((0,5,2));
currentlight=(3,3,5);

pen p=rgb(0.1,0.1,0.58);
transform3 t=rotate(angle,(0,0,0),(1,0.25,0.25));

filldraw(box((-R-0.5,-R-0.5),(R+0.5,R+0.5)), p, 3mm+black+miterjoin);

revolution r=sphere(O,R);
draw(surface(r),p);

for (int phi=0; phi<360; phi+=angle) {
bool[] back,front;
save();

for (int i=0; i<nbpts; ++i) {
P[i]=t*P[i];
bool test=dot(P[i],currentprojection.camera) > 0;
front.push(test);
}

draw(segment(P,front,operator ..),linewidth(1mm));
draw(segment(P,!front,operator ..),grey);
restore();
}

A.movie(options="-density 350 -resample 96 -quality 100 -depth 8 -strip");

```

Étiquettes : , , , , , ,

## Animation with Asymptote – fig0090

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

 (Compiled with Asymptote version 1.86svn-r4626)
```
size(0,10cm);
import graph3;
import animation;
import solids;

currentlight.background=black;
settings.render=0;
animation A;
A.global=false;

int nbpts=500;
real q=2/5;
real pas=5*2*pi/nbpts;
int angle=4;
real R=0.5;
pen p=rgb(0.1,0.1,0.58);
triple center=(1,1,1);
transform3 T=rotate(angle,center,center+X+0.25*Y+0.3*Z);

real x(real t){return center.x+R*cos(q*t)*cos(t);}
real y(real t){return center.y+R*cos(q*t)*sin(t);}
real z(real t){return center.z+R*sin(q*t);}

currentprojection=orthographic(1,1,1);
currentlight=(0,center.y-0.5,2*(center.z+R));

triple U=(center.x+1.1*R,0,0), V=(0,center.y+1.1*R,0);
path3 xy=plane(U,V,(0,0,0));
path3 xz=rotate(90,X)*xy;
path3 yz=rotate(-90,Y)*xy;

triple[] P;
path3 curve;
real t=-pi;
for (int i=0; i < nbpts; ++i) {
t+=pas;
triple M=(x(t),y(t),z(t));
P.push(M);
curve = curve..M;
}

curve=curve..cycle;

draw(surface(xy), grey);
draw(surface(xz), grey);
draw(surface(yz), grey);

triple xyc=(center.x,center.y,0);
path3 cle=shift(xyc)*scale3(R)*unitcircle3;
surface scle=surface(cle);
draw(scle, black);
draw(rotate(90,X)*scle, black);
draw(rotate(-90,Y)*scle, black);

draw(surface(sphere(center,R)), p);

triple vcam=1e5*currentprojection.camera-center;
for (int phi=0; phi<360; phi+=angle) {
bool[] back,front;
save();

for (int i=0; i<nbpts; ++i) {
P[i]=T*P[i];
bool test=dot(P[i]-center,vcam) > 0;
front.push(test);
}

curve=T*curve;
draw(segment(P,front,operator ..), paleyellow);
draw(segment(P,!front,operator ..),0.5*(paleyellow+p));
draw((planeproject(xy)*curve)^^
(planeproject(xz)*curve)^^
(planeproject(yz)*curve), paleyellow);

restore();
}

A.movie(options="-density 350 -resample 96 -quality 100 -depth 8 -strip");

```

## Animation with Asymptote – fig0150

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

 (Compiled with Asymptote version 1.86svn-r4626)
Movie flash (swf)
This animation is available in the Syracuse web site.
```
/*Inspiration*/
import Lsystem;
import animate;

settings.tex="pdflatex";
settings.outformat="pdf";

animation A;
size(10cm,0);

string[][] rules={{"X","^<XF^<XFX-F^>>XFX&F+>>XFX-F>X->"}};
Lsystem3 HilbertCurve3D=Lsystem3("X", rules, La=90, Lai=0);
HilbertCurve3D.iterate(3);

path3[] g=HilbertCurve3D.paths3();
triple M=(max(g)+min(g))/2;
currentprojection=currentprojection=orthographic((10,10,6));

for (int angle=0; angle < 360; angle += 2) {
save();
draw(rotate(angle,M,M+Z)*g[0], linewidth(bp)+0.9*yellow);