## Asymptote using tube.asy – fig0010

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
size(12cm,0);

currentprojection=orthographic(0,0.5,1);

// The tube's section used is a path (here an U);
path section=rotate(90)*(N+W--W--E--N+E);

// The tubed curve (yellow tube) has three nodes joined with cubic spline:
path3 p=shift(20X)*scale(10,20,1)*(X..Y..X+Y..cycle);

// A tube is a surface, here the tube is drawn in yellow with purple meshes.
draw(tube(p,section), yellow, bp+purple);
draw(p,red); dot(p);

// The tubed curve (purple tube) has three nodes joined with linear segments:
path3 p=scale(10,20,1)*(X--Y--(X+Y)--cycle);

// Here the tube is drawn in purple with yellow meshes.
draw(tube(p,scale(2)*section), purple, bp+yellow);
draw(p,red); dot(p);



Étiquettes :

## Asymptote using tube.asy – fig0020

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
size(10cm,0);

currentprojection=orthographic(0,0.5,1);
path section=rotate(90)*(N+W--W--E--N+E);

// The tubed curve has three nodes joined with linear segments.
path3 p=scale(10,20,1)*(X--Y--(X+Y)--cycle);

// We may use the routine roundedpath in order to obtain rounded corner:
draw(tube(roundedpath(p,r=0.05),
section,
corner=100), // Controls the number of elementary tubes at the corners
purple, bp+yellow+thin());
draw(p,red); dot(p);



Étiquettes :

## Asymptote using tube.asy – fig0030

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
size(10cm,0);

currentprojection=orthographic(0,0.5,1);
path section=rotate(180)*(N+W--W--E--N+E);

path3 p=scale(5,10,1)*unitcircle3;

draw(tube(p, section,
relstep=1/6), // Fix the sample step of the relative time (reltime) of the elementary tubes.
purple, bp+yellow);
draw(p,red); dot(p);



Étiquettes :

## Asymptote using tube.asy – fig0040

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;

size(10cm,0);
currentprojection=perspective(4,3,4);

triple f(real t){
return t*Z+(cos(2pi*t),sin(2pi*t),0)/sqrt(1+0.5*t^2);
}

path3 p=graph(f,0,2.7,operator ..);
draw(tube(p,scale(0.2)*polygon(5)), purple);



Étiquettes : ,

## Asymptote using tube.asy – fig0050

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;

size(10cm,0);
currentprojection=perspective(4,3,4);
real x(real t) {return (1/sqrt(1+0.5*t^2))*cos(2pi*t);}
real y(real t) {return (1/sqrt(1+0.5*t^2))*sin(2pi*t);}
real z(real t) {return t;}

path3 p=graph(x,y,z,0,2.7,operator ..);
path section=scale(0.2)*polygon(5);

// tube.asy defines a "colored path".
// The value of coloredtype may be coloredSegments or coloredNodes.
// Here the path scale(0.2)*polygon(5) has fixed colored SEGMENTS.
coloredpath cp=coloredpath(section,
// The array of pens become automatically cyclic.
new pen[]{0.8*red, 0.8*blue, 0.8*yellow, 0.8*purple, black},
colortype=coloredSegments);

// Draw the tube, each SEGMENT of the section is colored.
draw(tube(p,cp));



Étiquettes : , ,

## Asymptote using tube.asy – fig0060

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;

size(10cm,0);
currentprojection=perspective(4,3,4);
real x(real t) {return (1/sqrt(1+0.5*t^2))*cos(2pi*t);}
real y(real t) {return (1/sqrt(1+0.5*t^2))*sin(2pi*t);}
real z(real t) {return t;}

path3 p=graph(x,y,z,0,2.7,operator ..);
path section=scale(0.2)*polygon(5);

// Here the path scale(0.2)*polygon(5) has colored NODES.
coloredpath cp=coloredpath(section,
new pen[]{0.8*red, 0.8*blue, 0.8*yellow, 0.8*purple, black},
colortype=coloredNodes);

// Draw the tube, each NODE of the section is colored.
draw(tube(p,cp));



Étiquettes : , ,

## Asymptote using tube.asy – fig0070

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;

size(10cm,0);
currentprojection=perspective(4,3,4);
real x(real t) {return (1/sqrt(1+0.5*t^2))*cos(2pi*t);}
real y(real t) {return (1/sqrt(1+0.5*t^2))*sin(2pi*t);}
real z(real t) {return t;}

path3 p=graph(x,y,z,0,2.7,operator ..);
path section=scale(0.2)*polygon(5);

// Define a pen wich depends of a real t. t represent the "reltime" of the path3 p.
pen pen(real t){
return interp(red,blue,1-2*abs(t-0.5));
}

// Here the section has colored segments (by default) depending to reltime.
draw(tube(p,coloredpath(section,pen)));



Étiquettes : , ,

## Asymptote using tube.asy – fig0080

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;
size(12cm,0);
currentprojection=perspective((-1,1,1));

int p=7, q=3;
real n=p/q;
real a=1, b=1;
real x(real t){return a*cos(t);}
real y(real t){return a*sin(t);}
real z(real t){return b*cos(n*t);}

real R(real t){
real st2=(n*sin(n*t))^2;
return a*(1+st2)^(1.5)/sqrt(1+st2+n^4*cos(n*t)^2);
// return -a*(1+st2)^(1.5)/sqrt(1+st2+n^4*cos(n*t)^2); // Signed radius curvature
}

real mt=q*2*pi;
path3 p=graph(x,y,z,0,mt,operator ..)..cycle;

real m=R(0), M=R(0.5*pi/n);

// Define a pen depending to the radius curvature of graph(x,y,z) at reltime t
pen curvaturePen(real t){
real r=abs(R(t*mt)-m)/(M-m);
return interp(red,blue,r);
}

// Draw the tube, colors depend of the radius curvature R.
draw(tube(p,coloredpath(scale(0.1)*unitcircle, curvaturePen)));



Étiquettes : , ,

## Asymptote using tube.asy – fig0090

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;

size(10cm,0);
currentprojection=perspective(4,3,4);
real x(real t) {return (1/sqrt(1+0.5*t^2))*cos(2pi*t);}
real y(real t) {return (1/sqrt(1+0.5*t^2))*sin(2pi*t);}
real z(real t) {return t;}

path3 p=graph(x,y,z,0,2.7,operator ..);
path section=scale(0.2)*polygon(4);

// Define an array of pen wich depends of a real t. t represent the "reltime" of the path3 p.
pen[] pens(real t){
return new pen[] {interp(blue,red,t),
interp(orange,yellow,t),
interp(green,orange,t),
interp(red,purple,t)};
}

// "pen[] pens(real t)" allows to color each nodes or segments with a real parameter (the reltime)
// Note that all arrays of pens are convert to cyclical arrays.
draw(tube(p,coloredpath(section,
pens,
colortype=coloredNodes)));



Étiquettes : , , ,

## Asymptote using tube.asy – fig0100

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;
size(12cm,0);
currentprojection=orthographic(4,3,2);

real x(real t) {return sin(t);}
real y(real t) {return cos(t);}
real z(real t) {return sqrt(t);}

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

path section=subpath(unitcircle,0,2);

pen pens(real t){
return interp(red,blue,t);
}

// Define a transformation wich will be applied to each section at reltime t.
transform T(real t){return scale(t^0.75/2);}

// Combination of pens and transform:
draw(tube(p,coloredpath(section,pens), T));
draw(p);



Étiquettes : ,

## Asymptote using tube.asy – fig0110

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;
size(12cm,0);
currentprojection=orthographic(4,3,4);

real x(real t) {return sin(t);}
real y(real t) {return 0.5*sin(2*t);}

path g=graph(x,y,0,2pi,50,operator ..);
path3 p=path3(scale(5)*g);

pen pen(real t){
return interp(red,blue,1-2*abs(t-0.5));
}

draw(tube(p,coloredpath(subpath(unitcircle,1,3),pen)));
draw(p);



Étiquettes :

## Asymptote using tube.asy – fig0120

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

 (Compiled with Asymptote version 2.14svn-r5318)

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

real x(real t) {return sin(t);}
real y(real t) {return 0.5*sin(2*t);}

path g=graph(x,y,0,2pi,50,operator ..);
path3 p=path3(scale(5)*g);

pen[] pens(real t){
real tt=1-2*abs(t-0.5);
return new pen[] {interp(red,blue,tt), interp(blue,red,tt)};
}

draw(tube(p,
coloredpath(polygon(5),pens,colortype=coloredNodes)));
label("colortype=coloredNodes",8*X);

draw(tube(shift(10*Y)*p,
coloredpath(polygon(5),pens,colortype=coloredSegments)));
label("colortype=coloredSegments",8*X+10Y);



Étiquettes : ,

## Asymptote using tube.asy – fig0130

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph;
size(12cm,0);
currentprojection=perspective(4,3,6);

real f(real t) {return cos(2*t);}
path g=polargraph(f,0,2pi,10,operator ..)&cycle;
path3 p=path3(scale(20)*g);

draw(tube(p,rotate(60)*polygon(3)), 0.8*red);
draw(tube(shift(Z)*p,scale(0.25)*unitcircle), orange);
draw(shift(1.25*Z)*p);



Étiquettes : , ,

## Asymptote using tube.asy – fig0140

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph;
size(12cm,0);
currentprojection=perspective(0,3,6);

real f(real t) {return cos(2*t);}
path g=polargraph(f,0,2pi,10,operator --)&cycle;
path3 p=path3(scale(20)*g);

draw(tube(p,2W--2E), red, bp+black);
draw(tube(p,unitcircle), orange, bp+black);



Étiquettes : , ,

## Asymptote using tube.asy – fig0150

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;
size(12cm,0);
// currentprojection=perspective((2,1,6),-Z); real q=1;
currentprojection=perspective((-1,1,1)); real q=2;

real x(real t){return (1-cos(t))*cos(q*t);}
real y(real t){return (1-cos(t))*sin(q*t);}
real z(real t){return cos(3t);}

path3 p=graph(x,y,z,0,2pi,20,operator ..);
draw(tube(p,scale(0.4,0.1)*unitcircle), purple);



Étiquettes :

## Asymptote using tube.asy – fig0160

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;
size(12cm,0);

currentprojection=perspective(1,-1,0);

real x(real t)
{
return 41*cos(t)-18*sin(t)-83*cos(2t)-83*sin(2t)-11*cos(3t)+27*sin(3t);
}

real y(real t)
{
return 36*cos(t)+27*sin(t)-113*cos(2t)+30*sin(2t)+11*cos(3t)-27*sin(3t);
}

real z(real t)
{
return 45*sin(t)-30*cos(2t)+113*sin(2t)-11*cos(3t)+27*sin(3t);
}

path3 p=scale3(0.05)*graph(x,y,z,-pi,pi,200,operator --)&cycle;

path section=scale(2,0.5)*unitcircle;
// path section=scale(2,0.5)*polygon(4);
// path section=scale(2)*polygon(6);
draw(tube(p,section), purple);



Étiquettes :

## Asymptote using tube.asy – fig0170

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;
size(12cm,0);

currentprojection=perspective(1,-1,0);

path3 p=scale3(20)*randompath3(20,false,operator--)--cycle;

path section=scale(1,0.5)*unitcircle;
// path section=polygon(6);
// path section=scale(1,0.25)*polygon(4);
draw(tube(p,section), purple, bp+yellow);



Étiquettes :

## Asymptote using tube.asy – fig0180

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import graph3;
size(12cm,0);

currentprojection=perspective(1,-1,0);

path3 p=scale3(20)*randompath3(20,false,operator--)--cycle;

path section=scale(1,0.25)*polygon(4);
draw(tube(roundedpath(p,0.05),section, corner=10), purple);



Étiquettes :

## Asymptote using tube.asy – fig0190

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

 (Compiled with Asymptote version 2.14svn-r5318)

import tube;
import solids;

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

int p=8, q=3;
real n=p/q, R=2, r=1;

real x(real t){return (R+r*cos(n*t))*cos(t);}
real y(real t){return (R+r*cos(n*t))*sin(t);}
real z(real t){return r*sin(n*t);}

path3 p=graph(x,y,z,0,6pi,200,operator ..)&cycle;

revolution torus=revolution(Circle(R*X,r,Y,10),Z);

transform T(real t){return scale(0.3+0.25*sin(t*20pi));}

pen[] bpen={0.5red,0.5blue};
bpen.cyclic=true;
pen pen(real t){return bpen[ceil(sin(t*20pi)-1e-3)];}

draw(tube(p,coloredpath(polygon(3),pen),T));
// draw(surface(torus),yellow);



Étiquettes :

## Asymptote using tube.asy – fig0200

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

 (Compiled with Asymptote version 2.14svn-r5318)

// Anneau de Borrommée
// Borromean rings

import tube;
import solids;

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

real a=5, b=2, sq3=sqrt(3);
for (int i=0; i <= 2; ++i) {
real ai, bi;
if(i == 0) {
ai=a/2;
bi=a*sq3/2;
} else if(i == 1) {
ai=-a/2;
bi=a*sq3/2;
} else {
ai=0;
bi=a*sq3;
}
real x(real t){return a*cos(t)+ai;}
real y(real t){return a*sin(t)+bi;}
real z(real t){return b*cos(3t);}

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

real trig(real t){return 1-2*abs(t%1-0.5);}
pen pens(real t) {
real tt=trig(t+i/3);
return interp(red,yellow,(tt));
}

draw(tube(p, coloredpath(polygon(4),pens)));
}



É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 : , , ,

## Unofficial package tube_js.asy – fig0010

Category: Asymptote,tube_js.asy,Unofficial packagesPh. Ivaldi @ 22 h 03 min

 (Compiled with Asymptote version 2.14svn-r5318)

/* Author: Jens Schwaiger */
settings.render=0;
import tube_js;

size(10cm,0);
currentprojection=perspective(4,3,4);
real x(real t) {return (1/sqrt(1+0.5*t^2))*cos(2pi*t);}
real y(real t) {return (1/sqrt(1+0.5*t^2))*sin(2pi*t);}
real z(real t) {return 0.9*t;}

path3 p=graph(x,y,z,0,2.7,Spline);

draw(spacetube(p,100,16), orange, 1bp+black);



Étiquettes : ,

## Unofficial package tube_js.asy – fig0020

Category: Asymptote,tube_js.asy,Unofficial packagesPh. Ivaldi @ 23 h 03 min

 (Compiled with Asymptote version 2.14svn-r5318)

/* Author: Jens Schwaiger */
settings.render=0;
import tube_js;

size(10cm,0);
currentprojection=perspective(4,3,4);

guide3 p=roundedguide((1,0,0)--(0,0,0)--(0,0,1)--(0,1,1)--cycle,.4);
p=rotate(30,Y)*p;

guide cs(real s){return scale(0.15)*unitsquare;};

draw(spacetube(p,120,32,cs), lightblue, black);



Étiquettes : ,

## Unofficial package tube_js.asy – fig0030

Category: Asymptote,tube_js.asy,Unofficial packagesPh. Ivaldi @ 0 h 03 min

 (Compiled with Asymptote version 2.14svn-r5318)

/* Author: Jens Schwaiger */
settings.render=0;
import tube_js;

size(10cm,0);
currentprojection=perspective(4,3,4);
currentlight=(0,0.10,1.3);

real x(real t) {return (1/sqrt(1+0.5*t^2))*cos(2pi*t);}
real y(real t) {return (1/sqrt(1+0.5*t^2))*sin(2pi*t);}
real z(real t) {return 0.9*t;}
path3 p=graph(x,y,z,1,2.7,Spline);

guide cs(real u)
{
int m=-6;
real x(real t){ return (1+1/m)*cos(t)-(1/m)*(0.7(1-u))*cos((1+m)*t);};
real y(real t){ return (1+1/m)*sin(t)-(1/m)*(0.7(1-u))*sin((1+m)*t);};
return scale(0.25)*(graph(x,y,0,2pi)..cycle);
}

draw(spacetube(p,120,24,cs,cover=true,twist=0), orange,black);

if(!is3D())



Étiquettes : ,

## Unofficial package tube_js.asy – fig0040

Category: Asymptote,tube_js.asy,Unofficial packagesPh. Ivaldi @ 1 h 03 min

 (Compiled with Asymptote version 2.14svn-r5318)

// settings.render=0;
import tube_js;

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

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

path3 p=scale3(4)*graph(x,y,z,0,2*pi,Spline)--cycle;
guide arc=graph(x,y,0,2*pi)--cycle;
guide cs(real s){return arc;};

draw(spacetube(p,200,100,cs,twist=0), 0.8*blue, invisible);

if(!is3D())



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

path sec=scale(0.25)*texpath("$\pi$")[0];