Asymptote using graph3.asy – fig0010

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 3 h 11 min

Figure 0001

A Möbius strip of half-width latex2png equation with midcircle of radius latex2png equation and at height latex2png equation can be represented parametrically by:

latex2png equation

for latex2png equation in latex2png equation and latex2png equation in latex2png equation. In this parametrization, the Möbius strip is therefore a cubic surface with equation

latex2png equation

Source

(Compiled with Asymptote version 1.87svn-r4652)
    
import graph3;
ngraph=200;
size(12cm,0);
currentprojection=orthographic(-4,-4,5);

real x(real t), y(real t), z(real t);

real R=2;
void xyzset(real s){
  x=new real(real t){return (R+s*cos(t/2))*cos(t);};
  y=new real(real t){return (R+s*cos(t/2))*sin(t);};
  z=new real(real t){return s*sin(t/2);};
}


int n=ngraph;
real w=1;
real s=-w, st=2w/n;
path3 p;
triple[][] ts;
for (int i=0; i <= n; ++i) {
  xyzset(s);
  p=graph(x,y,z,0,2pi);

  ts.push(new triple[] {});
  for (int j=0; j <= ngraph; ++j) {
    ts[i].push(point(p,j));
  }
  s += st;
}

pen[] pens={black, yellow, red, yellow, black};
draw(surface(ts, new bool[][]{}), lightgrey);
for (int i=0; i <= 4; ++i) {
  xyzset(-w+i*w/2);
  draw(graph(x,y,z,0,2pi), 2bp+pens[i]);
}

Mots-clefs : , ,


Asymptote using graph3.asy – fig0020

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 4 h 11 min

Figure 0002
(Compiled with Asymptote version 1.87svn-r4652)
    
import graph3;

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

limits((0,-2,0),(2,2,2));

xaxis3("$x$", OutTicks());
yaxis3("$y$", OutTicks());
zaxis3("$z$", OutTicks());

Mots-clefs : ,


Asymptote using graph3.asy – fig0030

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 5 h 11 min

Figure 0003
(Compiled with Asymptote version 1.87svn-r4652)
    
import graph3;

size(8cm,0,IgnoreAspect);
currentprojection=orthographic(1,1,1);

limits((0,-2,0), (2,2,2));

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

Mots-clefs : ,


Asymptote using graph3.asy – fig0040

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 6 h 11 min

Figure 0004
(Compiled with Asymptote version 1.87svn-r4652)
    
import graph3;

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

defaultpen(overwrite(SuppressQuiet));

limits((0,-2,0),(2,2,2));

xaxis3("$x$", InTicks(XY()*Label));
yaxis3("$y$", InTicks(XY()*Label));
zaxis3("$z$", OutTicks, p=red, arrow=Arrow3);

Mots-clefs : ,


Asymptote using graph3.asy – fig0050

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 7 h 11 min

Figure 0005
(Compiled with Asymptote version 1.87svn-r4652)
    
import graph3;

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

limits((-2,-2,0),(0,2,2));

xaxis3(Label("$x$",MidPoint), OutTicks());
yaxis3("$y$", InTicks());
zaxis3("$z$",XYEquals(-2,0), OutTicks());

Mots-clefs : ,


Asymptote using graph3.asy – fig0060

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 8 h 11 min

Figure 0006
(Compiled with Asymptote version 1.87svn-r4652)
    
import graph3;
usepackage("icomma");

size(8cm,0);
currentprojection=orthographic(1.5,1,1);

limits((-2,-1,-.5), (0,1,1.5));

xaxis3("$x$",
       Bounds(Both,Value),
       OutTicks(endlabel=false));

yaxis3("$y$",
       Bounds(Both,Value),
       OutTicks(Step=.5,step=.25));

zaxis3("$z$", XYEquals(-2,0), InOutTicks(Label(align=Y-X)));

dot(Label("",align=Z), (-1,0,0), red);

Mots-clefs : ,


Asymptote using graph3.asy – fig0070

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 9 h 11 min

Figure 0007
(Compiled with Asymptote version 1.87svn-r4652)
    
import graph3;

size(8cm,0);
currentprojection=orthographic(1,1,0.5);
limits((-2,-2,0),(0,2,2));

xaxis3(Label("$x$",align=Z),
       Bounds(Min,Min),
       OutTicks(endlabel=false,Step=1,step=0.5));

yaxis3("$y$", Bounds(),
       OutTicks(pTick=0.8*red, ptick=lightgrey));

zaxis3("$z$", Bounds(),
       OutTicks, p=red, arrow=Arrow3);

dot(Label("",align=Z), (-1,0,0), red);

Mots-clefs : , ,


Asymptote using graph3.asy – fig0080

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 10 h 11 min

Figure 0008
(Compiled with Asymptote version 1.87svn-r4652)
    
// 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);
currentlight=adobe;

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

Mots-clefs : , , , ,


Asymptote using graph3.asy – fig0090

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 11 h 11 min

Figure 0009
(Compiled with Asymptote version 1.87svn-r4652)
    
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)));

Mots-clefs : , , , , ,


Asymptote using graph3.asy – fig0110

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 13 h 11 min

Figure 0011
(Compiled with Asymptote version 1.87svn-r4652)
    
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)));

Mots-clefs : , , , , , , , , , ,


Asymptote using graph3.asy – fig0120

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 14 h 11 min

Figure 0012
(Compiled with Asymptote version 1.87svn-r4652)
    
import graph3;
import palette;

real sinc(real x){return x != 0 ? sin(x)/x : 1;}

real f(pair z){
  real value = (sinc(pi*z.x)*sinc(pi*z.y))**2;
  return value^0.25;
}

currentprojection=orthographic(0,0,1);

size(10cm,0);

surface s=surface(f,(-5,-5),(5,5),100,Spline);
s.colors(palette(s.map(zpart),Gradient((int)2^11 ... new pen[]{black,white})));

draw(planeproject(unitsquare3)*s,nolight);

Mots-clefs : , , , , ,


Asymptote using graph3.asy – fig0130

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 15 h 11 min

Figure 0013
(Compiled with Asymptote version 1.87svn-r4652)
    
/*From TeXgraph exemples*/
settings.render=0;
import graph3;
import palette;
size(10cm,0);
currentprojection=orthographic(2,-2,2.5);

real f(pair z) {
  real u=z.x, v=z.y;
  return (u/2+v)/(2+cos(u/2)*sin(v));
}

surface s=surface(f,(0,0),(14,14),150,Spline);
draw(s,mean(palette(s.map(zpart),Gradient(yellow,red))));

if(!is3D())
  shipout(bbox(3mm,Fill(black)));

Mots-clefs : , , ,


Asymptote using graph3.asy – fig0140

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 16 h 11 min

Figure 0014
(Compiled with Asymptote version 1.87svn-r4652)
    
/*From TeXgraph exemples*/
settings.render=0;
import graph3;
import palette;
size(10cm,0);
currentprojection=orthographic(2,-2,2.5);

real f(pair z) {
  real u=z.x, v=z.y;
  return (u/2+v)/(2+cos(u/2)*sin(v));
}

surface s=surface(f,(0,0),(14,14),50,Spline);
s.colors(palette(s.map(zpart),Gradient(yellow,red)));

draw(s);

if(!is3D())
  shipout(bbox(3mm,Fill(black)));

Mots-clefs : , , ,


Asymptote using graph3.asy – fig0150

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 17 h 11 min

Figure 0015
(Compiled with Asymptote version 1.49svn-r3685)
    
settings.render=0;
import graph3;
size(10cm);

currentprojection=orthographic(4,2,4);

real r(real Theta, real Phi){return 1+0.5*(sin(2*Theta)*sin(2*Phi))^2;}
triple f(pair z) {return r(z.x,z.y)*expi(z.x,z.y);}

pen[] pens(triple[] z)
{
  return sequence(new pen(int i) {
      real a=abs(z[i]);
      return a < 1+1e-3 ? black : interp(blue, red, 2*(a-1));
    },z.length);
}

surface s=surface(f,(0,0),(pi,2pi),100,Spline);
// Interpolate the corners, and coloring each patch with one color
// produce some artefacts
draw(s,pens(s.cornermean()));

if(!is3D())
  shipout(bbox(3mm,Fill(black)));

Mots-clefs : , , , , ,


Asymptote using graph3.asy – fig0160

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 18 h 11 min

Figure 0016
(Compiled with Asymptote version 1.49svn-r3685)
    
settings.render=0;
import graph3;
size(10cm);

currentprojection=orthographic(4,2,4);

real r(real Theta, real Phi){return 1+0.5*(sin(2*Theta)*sin(2*Phi))^2;}
triple f(pair z) {return r(z.x,z.y)*expi(z.x,z.y);}

pen[][] pens(triple[][] z)
{
  pen[][] p=new pen[z.length][];
  for(int i=0; i < z.length; ++i) {
    triple[] zi=z[i];
    p[i]=sequence(new pen(int j) {
        real a=abs(zi[j]);
        return a < 1+1e-3 ? black : interp(blue, red, 2*(a-1));},
      zi.length);
  }
  return p;
}

surface s=surface(f,(0,0),(pi,2pi),100,Spline);
// Here we interpolate the pens, this looks smoother, with fewer artifacts
draw(s,mean(pens(s.corners())));

if(!is3D())
  shipout(bbox(3mm,Fill(black)));

Mots-clefs : , , , , ,


Asymptote using graph3.asy – fig0170

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 19 h 11 min

Figure 0017
(Compiled with Asymptote version 1.49svn-r3685)
    
settings.render=0;
import graph3;
size(10cm);

currentprojection=orthographic(4,2,4);

real r(real Theta, real Phi){return 1+0.5*(sin(2*Theta)*sin(2*Phi))^2;}
triple f(pair z) {return r(z.x,z.y)*expi(z.x,z.y);}

pen[][] pens(triple[][] z)
{
  pen[][] p=new pen[z.length][];
  for(int i=0; i < z.length; ++i) {
    triple[] zi=z[i];
    p[i]=sequence(new pen(int j) {
        real a=abs(zi[j]);
        return a < 1+1e-3 ? black : interp(blue, red, 2*(a-1));},
      zi.length);
  }
  return p;
}

surface s=surface(f,(0,0),(pi,2pi),100,Spline);
// Here we determine the colors of vertexes (vertex shading).
// Since the PRC output format does not support vertex shading of Bezier surfaces, PRC patches
// are shaded with the mean of the four vertex colors.
s.colors(pens(s.corners()));
draw(s);

if(!is3D())
  shipout(bbox(3mm,Fill(black)));

Mots-clefs : , , , , ,


Asymptote using graph3.asy – fig0180

Catégorie : Asymptote, Examples 3D, graph3.asyPh. Ivaldi @ 20 h 11 min

Figure 0018

The spherical harmonics latex2png equation are the angular portion of the solution to Laplace's equation in spherical coordinates where azimuthal symmetry is not present.

The spherical harmonics are defined by:

latex2png equation

where latex2png equation and latex2png equation is the Legendre polynomial.

Source

(Compiled with Asymptote version 1.87svn-r4652)
    
import palette;
import math;
import graph3;

typedef real fct(real);
typedef pair zfct2(real,real);
typedef real fct2(real,real);

real binomial(real n, real k)
{
  return gamma(n+1)/(gamma(n-k+1)*gamma(k+1));
}

real factorial(real n) {
  return gamma(n+1);
}

real[] pdiff(real[] p)
{ // p(x)=p[0]+p[1]x+...p[n]x^n
  // retourne la dérivée de p
  real[] dif;
  for (int i : p.keys) {
    if(i != 0) dif.push(i*p[i]);
  }
  return dif;
}

real[] pdiff(real[] p, int n)
{ // p(x)=p[0]+p[1]x+...p[n]x^n
  // dérivée n-ième de p
  real[] dif={0};
  if(n >= p.length) return dif;
  dif=p;
  for (int i=0; i < n; ++i)
    dif=pdiff(dif);
  return dif;
}

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

zfct2 operator +(zfct2 f, zfct2 g)
{// Défini f+g
  return new pair(real t, real p){return f(t,p)+g(t,p);};
}

zfct2 operator -(zfct2 f, zfct2 g)
{// Défini f-g
  return new pair(real t, real p){return f(t,p)-g(t,p);};
}

zfct2 operator /(zfct2 f, real x)
{// Défini f/x
  return new pair(real t, real p){return f(t,p)/x;};
}

zfct2 operator *(real x,zfct2 f)
{// Défini x*f
  return new pair(real t, real p){return x*f(t,p);};
}

fct fct(real[] p)
{ // convertit le tableau des coefs du poly p en fonction polynôme
  return new real(real x){
    real y=0;
    for (int i : p.keys) {
      y += p[i]*x^i;
    }
    return y;
  };
}

real C(int l, int m)
{
  if(m < 0) return 1/C(l,-m);
  real OC=1;
  int d=l-m, s=l+m;
  for (int i=d+1; i <=s ; ++i) OC *= i;
  return 1/OC;
}

int csphase=-1;
fct P(int l, int m)
{ // Polynôme de Legendre associé
  // http://mathworld.wolfram.com/LegendrePolynomial.html
  if(m < 0) return (-1)^(-m)*C(l,-m)*P(l,-m);
  real[] xl2;
  for (int k=0; k <= l; ++k) {
    xl2.push((-1)^(l-k)*binomial(l,k));
    if(k != l) xl2.push(0);
  }
  fct dxl2=fct(pdiff(xl2,l+m));
  return new real(real x){
    return (csphase)^m/(2^l*factorial(l))*(1-x^2)^(m/2)*dxl2(x);
  };
}

zfct2 Y(int l, int m)
{// http://fr.wikipedia.org/wiki/Harmonique_sph%C3%A9rique#Expression_des_harmoniques_sph.C3.A9riques_normalis.C3.A9es
  return new pair(real theta, real phi) {
    return sqrt((2*l+1)*C(l,m)/(4*pi))*P(l,m)(cos(theta))*expi(m*phi);
  };
}

real xyabs(triple z){return abs(xypart(z));}

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

zfct2 Ylm;

triple F(pair z)
{
  //   real r=0.75+dot(0.25*I,Ylm(z.x,z.y));
  //   return r*expi(z.x,z.y);
  real r=abs(Ylm(z.x,z.y))^2;
  return r*expi(z.x,z.y);
}

int nb=4;
for (int l=0; l < nb; ++l) {
  for (int m=0; m <= l; ++m) {
    Ylm=Y(l,m);

    surface s=surface(F,(0,0),(pi,2pi),60);
    s.colors(palette(s.map(xyabs),Rainbow()));

    triple v=(-m,0,-l);
    draw(shift(v)*s);
    label("$Y_"+ string(l) + "^" + string(m) + "$:",shift(X/3)*v);
  }
}

Mots-clefs : , , , , ,


Asymptote using grid3.asy – fig0100

Catégorie : Asymptote, Examples 3D, grid3.asyPh. Ivaldi @ 20 h 09 min

Figure 0001
(Compiled with Asymptote version 1.87svn-r4652)
    
import grid3;

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

limits((-2,-2,0), (0,2,2));

grid3(
      pic=currentpicture,            // picture (default=currentpicture)

      gridroutine=XYZgrid(           // gridtype3droutine or gridtype3droutine [] (alias gridtype3droutines)
                          //                         or gridtype3droutines []:
                          //                         The routine(s) to draw the grid(s);
                          //                         the values can be as follows:
                          //                            * XYgrid : draw grid from X in direction of Y
                          //                            * YXgrid : draw grid from Y in direction of X
                          //                                etc...
                          //                            * An array of previous values XYgrid, YXgrid, ...
                          //                            * XYXgrid : draw XYgrid and YXgrid grids
                          //                            * YXYgrid : draw XYgrid and YXgrid grids
                          //                            * ZXZgrid : draw ZXgrid and XZgrid grids
                          //                            * YX_YZgrid : draw YXgrid and YZgrid grids 
                          //                            * XY_XZgrid : draw XYgrid and XZgrid grids 
                          //                            * YX_YZgrid : draw YXgrid and YZgrid grids 
                          //                            * An array of previous values XYXgrid, YZYgrid, ...
                          //                            * XYZgrid : draw XYXgrid, ZYZgrid and XZXgrid grids.
                          pos=Relative(0)), // position (default=Relative(0)) :
      //                          this is the position of the grid relatively to
      //                          the perpendicular axe of the grid.
      //                          If 'pos' is a the real, 'pos' is a coordinate relativly to this axe.
      //                          Alias 'top=Relative(1)', 'middle=Relative(0.5)'
      //                          and 'bottom=Relative(0)' can be used as value.

      // Following arguments are similar as the function 'Ticks'.
      N=0,                // int (default=0)
      n=0,                // int (default=0)
      Step=0,             // real (default=0)
      step=0,             // real (default=0)
      begin=true,         // bool (default=true)
      end=true,           // bool (default=true)
      pGrid=grey,         // pen (default=grey)
      pgrid=lightgrey,    // pen (default=lightgrey)
      put=Below           // bool (default=Below)
      );

xaxis3(Label("$x$",position=EndPoint,align=S), Bounds(Min,Min), OutTicks());
yaxis3(Label("$y$",position=EndPoint,align=S), Bounds(Min,Min), OutTicks());
zaxis3(Label("$z$",position=EndPoint,align=(0,0.5)+W), Bounds(Min,Min), OutTicks(beginlabel=false));

Mots-clefs : , ,


Asymptote using grid3.asy – fig0200

Catégorie : Asymptote, Examples 3D, grid3.asyPh. Ivaldi @ 21 h 09 min

Figure 0002
(Compiled with Asymptote version 1.87svn-r4652)
    
import grid3;

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

limits((-2,-2,0), (0,2,2));

scale(Linear, Linear, Log(automax=false));
grid3(XZXgrid);
grid3(XYXgrid);
xaxis3(Label("$x$",position=EndPoint,align=S), Bounds(Min,Min), OutTicks());
yaxis3(Label("$y$",position=EndPoint,align=S), Bounds(Min,Min), OutTicks());
zaxis3(Label("$z$",position=EndPoint,align=(0,0.5)+W), Bounds(Min,Min), OutTicks(beginlabel=false));

Mots-clefs : , ,


Asymptote using grid3.asy – fig0300

Catégorie : Asymptote, Examples 3D, grid3.asyPh. Ivaldi @ 22 h 09 min

Figure 0003
(Compiled with Asymptote version 1.87svn-r4652)
    
import grid3;

size(10cm,0,IgnoreAspect);
currentprojection=orthographic(0.25, 1, 0.25);
limits((-2,-2,0), (0,2,2));

grid3(new grid3routines [] {XYXgrid(Relative(1)), XZXgrid(0)});

xaxis3(Label("$x$",position=EndPoint,align=S), Bounds(Min,Min), OutTicks());
yaxis3(Label("$y$",position=EndPoint,align=S), Bounds(Min,Min), OutTicks());
zaxis3(Label("$z$",position=EndPoint,align=(0,.5)+W), Bounds(Min,Min), OutTicks(beginlabel=false));

Mots-clefs : , ,


Asymptote using grid3.asy – fig0400

Catégorie : Asymptote, Examples 3D, grid3.asyPh. Ivaldi @ 23 h 09 min

Figure 0004
(Compiled with Asymptote version 1.87svn-r4652)
    
import grid3;

size(10cm,0,IgnoreAspect);
currentprojection=orthographic(0.25, 1, 0.25);
limits((-2,-2,0),(0,2,2));

grid3(new grid3routines [] {XYXgrid(-0.5), XYXgrid(1.5)},
      pGrid=new pen[] {red, blue},
      pgrid=new pen[] {0.5red, 0.5blue});
xaxis3(Label("$x$",position=EndPoint,align=Z), YZEquals(-2,0), OutTicks());
yaxis3(Label("$y$",position=EndPoint,align=Z), XZEquals(-2,0), OutTicks());
zaxis3(Label("$z$",position=EndPoint,align=X), XYEquals(-2,-2), OutTicks(Label("",align=-X-Y)));

Mots-clefs : , ,


Asymptote using grid3.asy – fig0500

Catégorie : Asymptote, Examples 3D, grid3.asyPh. Ivaldi @ 0 h 09 min

Figure 0005
(Compiled with Asymptote version 1.87svn-r4652)
    
import grid3;

size(10cm,0,IgnoreAspect);
currentprojection=orthographic(0.25,1,0.25);
limits((-2,-2,0),(0,2,2));

real Step=0.5, step=0.25;
xaxis3(Label("$x$",position=EndPoint,align=Z), YZEquals(-2,0),
       InOutTicks(Label(align=0.5*(Z-Y)),
                  Step=Step, step=step,
                  gridroutine=XYgrid,
                  pGrid=red, pgrid=0.5red));

yaxis3(Label("$y$",position=EndPoint,align=Z), XZEquals(-2,0),
       InOutTicks(Label(align=-0.5*(X-Z)), Step=Step, step=step,
                  gridroutine=YXgrid,
                  pGrid=red, pgrid=0.5red));

zaxis3("$z$", XYEquals(-1,0), OutTicks(Label(align=-0.5*(X+Y))));

Mots-clefs : , ,


Asymptote using grid3.asy – fig0600

Catégorie : Asymptote, Examples 3D, grid3.asyPh. Ivaldi @ 1 h 09 min

Figure 0006
(Compiled with Asymptote version 1.87svn-r4652)
    
import grid3;

size(10cm,0,IgnoreAspect);
currentprojection=orthographic(0.25,1,0.25);
limits((-2,-2,0),(0,2,2));

xaxis3(Label("$x$",position=EndPoint,align=Z), YZEquals(-2,0),
       OutTicks(Label(align=0.5*(Z-Y)),Step=0.5, gridroutine=XYgrid));

yaxis3(Label("$y$",position=EndPoint,align=-X), XZEquals(-2,0),
       InOutTicks(Label(align=0.5*(Z-X)),N=8,n=2, gridroutine=YX_YZgrid));

zaxis3("$z$", OutTicks(ZYgrid));

Mots-clefs : , ,


Asymptote using tube.asy – fig0040

Catégorie : Asymptote, Examples 3D, tube.asyPh. Ivaldi @ 23 h 11 min

Figure 0004
(Compiled with Asymptote version 1.87svn-r4652)
    
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);

Mots-clefs : ,


Asymptote using tube.asy – fig0050

Catégorie : Asymptote, Examples 3D, tube.asyPh. Ivaldi @ 0 h 11 min

Figure 0005
(Compiled with Asymptote version 1.87svn-r4652)
    
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));

Mots-clefs : , ,


Asymptote using tube.asy – fig0060

Catégorie : Asymptote, Examples 3D, tube.asyPh. Ivaldi @ 1 h 11 min

Figure 0006
(Compiled with Asymptote version 1.87svn-r4652)
    
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));

Mots-clefs : , ,


Asymptote using tube.asy – fig0070

Catégorie : Asymptote, Examples 3D, tube.asyPh. Ivaldi @ 2 h 11 min

Figure 0007
(Compiled with Asymptote version 1.87svn-r4652)
    
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)));

Mots-clefs : , ,


Asymptote using tube.asy – fig0080

Catégorie : Asymptote, Examples 3D, tube.asyPh. Ivaldi @ 2 h 11 min

Figure 0008
(Compiled with Asymptote version 1.87svn-r4652)
    
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)));

Mots-clefs : , ,


Asymptote using tube.asy – fig0090

Catégorie : Asymptote, Examples 3D, tube.asyPh. Ivaldi @ 3 h 11 min

Figure 0009
(Compiled with Asymptote version 1.87svn-r4652)
    
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)));

Mots-clefs : , , ,


Asymptote using tube.asy – fig0210

Catégorie : Asymptote, Examples 3D, tube.asyPh. Ivaldi @ 15 h 11 min

Figure 0021
(Compiled with Asymptote version 1.87svn-r4652)
    
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));

Mots-clefs : , , ,


Official Asymptote example – GaussianSurface

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 13 h 57 min

Figure 0007
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

size(200,0);

currentprojection=perspective(10,8,4);

real f(pair z) {return 0.5+exp(-abs(z)^2);}

draw((-1,-1,0)--(1,-1,0)--(1,1,0)--(-1,1,0)--cycle);

draw(arc(0.12Z,0.2,90,60,90,25),ArcArrow3);

surface s=surface(f,(-1,-1),(1,1),nx=5,Spline);

xaxis3(Label("$x$"),red,Arrow3);
yaxis3(Label("$y$"),red,Arrow3);
zaxis3(XYZero(extend=true),red,Arrow3);

draw(s,lightgray,meshpen=black+thick(),nolight);

label("$O$",O,-Z+Y,red);

Mots-clefs : , ,


Official Asymptote example – RiemannSurface

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 23 h 57 min

Figure 0017
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import palette;
       
size(200,300,keepAspect=false);
//settings.nothin=true;
       
currentprojection=orthographic(10,10,30);
currentlight=(10,10,5);
triple f(pair t) {return (exp(t.x)*cos(t.y),exp(t.x)*sin(t.y),t.y);}
       
surface s=surface(f,(-4,-2pi),(0,4pi),8,16,Spline);
s.colors(palette(s.map(zpart),Rainbow()));
draw(s);

Mots-clefs : , , , ,


Official Asymptote example – RiemannSurfaceRoot

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 0 h 57 min

Figure 0018
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
// Riemann surface of z^{1/n}
import graph3;
import palette;
 
int n=3;

size(200,300,keepAspect=false);
//settings.nothin=true; 
 
currentprojection=orthographic(10,10,30);
currentlight=(10,10,5);
triple f(pair t) {return (t.x*cos(t.y),t.x*sin(t.y),t.x^(1/n)*sin(t.y/n));}
 
surface s=surface(f,(0,0),(1,2pi*n),8,16,Spline);
s.colors(palette(s.map(zpart),Rainbow()));

draw(s,meshpen=black);

Mots-clefs : , , ,


Official Asymptote example – axis3

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 6 h 57 min

Figure 0024
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

size(0,200);
size3(200,IgnoreAspect);

currentprojection=perspective(5,2,2);

scale(Linear,Linear,Log);

xaxis3("$x$",0,1,red,OutTicks(2,2));
yaxis3("$y$",0,1,red,OutTicks(2,2));
zaxis3("$z$",1,30,red,OutTicks(beginlabel=false));

Mots-clefs : , ,


Official Asymptote example – cheese

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 15 h 57 min

Figure 0033
(Compiled with Asymptote version 1.87svn-r4652)
/* 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);

Mots-clefs : , , , , ,


Official Asymptote example – condor

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 21 h 57 min

Figure 0039
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
// Peter Luschny's Condor function
// http://www.luschny.de/math/asy/ElCondorYElGamma.html

import palette;
import graph3;

size(300,300,IgnoreAspect);
currentprojection=orthographic(0,-1,0,center=true);
currentlight=White;
real K=7;

triple condor(pair t)
{
  real y=t.y;
  real x=t.x*y;
  real e=gamma(y+1);
  real ymx=y-x;
  real ypx=y+x;
  real a=gamma((ymx+1)/2);
  real b=gamma((ymx+2)/2);
  real c=gamma((ypx+1)/2);
  real d=gamma((ypx+2)/2);
  real A=cos(pi*ymx);
  real B=cos(pi*ypx);
  return (x,y,log(e)+log(a)*((A-1)/2)+log(b)*((-A-1)/2)+log(c)*((B-1)/2)+
          log(d)*((-B-1)/2));
}

surface s=surface(condor,(-1,0),(1,K),16,Spline);
s.colors(palette(s.map(zpart),Rainbow()));

draw(s);

Mots-clefs : , , , ,


Official Asymptote example – elevation

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 17 h 57 min

Figure 0059
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import grid3;
import palette;

currentprojection=orthographic(0.8,1,1);

size(400,300,IgnoreAspect);

real f(pair z) {return cos(2*pi*z.x)*sin(2*pi*z.y);}

surface s=surface(f,(-1/2,-1/2),(1/2,1/2),50,Spline);

draw(s,mean(palette(s.map(zpart),Rainbow())),black);

grid3(XYZgrid);

Mots-clefs : , , , ,


Official Asymptote example – epix

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 19 h 57 min

Figure 0061
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

size(200,200,IgnoreAspect);

currentprojection=perspective(4,2,3);

real f(pair z) {return z.y^3/2-3z.x^2*z.y;}

draw(surface(f,(-1,-1),(1,1),nx=10,Spline),green);
draw(Label("$y$",1),(0,0,0)--(0,2,0),red,Arrow3);

draw(Label("$x$",1),(0,0,0)--(2,0,0),red,Arrow3);
draw(Label("$z$",1),(0,0,0)--(0,0,2.5),red,Arrow3);
label("$z=\frac{1}{2}y^3-3x^2y$",(1,1,1),NE);

Mots-clefs : , ,


Official Asymptote example – equilchord

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 21 h 57 min

Figure 0063
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

size(0,150);
currentprojection=perspective(5,-4,6);
currentlight=(-1,-1,2);
real t=0.5;

real F(pair z) {
  return (z.x^2+z.y^2 <= 1) ? sqrt(3)*(sqrt(1-z.x^2)-abs(z.y)) : 0; 
}

real a=1.5;
draw((-a,-a,0)--(-a,a,0)--(a,a,0)--(a,-a,0)--cycle,lightgray);

xaxis3(Label("$x$",1),red,Arrow3);
yaxis3(Label("$y$",1),red,Arrow3);
draw(circle((0,0,0),1),dashed);
draw(surface(F,(-1,-1),(t,1),20,monotonic),green,black);
real y=sqrt(1-t^2);
draw((t,y,0)--(t,-y,0)--(t,0,sqrt(3)*y)--cycle,blue);
label("$1$",(1,0,0),-Y+X);

Mots-clefs : , ,


Official Asymptote example – extrudedcontour

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 0 h 57 min

Figure 0066
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import contour;
import palette;
import graph3;
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);

for(guide p:g[0]){
  draw(extrude(p,8Z),palered);
  draw(path3(p),red+2pt);
}

draw(lift(f,g),red+2pt);

surface s=surface(f,(0,0),(10,10),20,Spline);
s.colors(palette(s.map(zpart),Rainbow()+opacity(0.5)));
draw(s);
axes3("$x$","$y$","$z$",Arrow3);


Mots-clefs : , , , ,


Official Asymptote example – filesurface

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 4 h 57 min

Figure 0070
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import palette;

size3(200,IgnoreAspect);

file in=line(input("filesurface.dat"));
real[] x=in;
real[] y=in;

real[][] f=dimension(in,0,0);

triple f(pair t) {
  int i=round(t.x);
  int j=round(t.y);
  return (x[i],y[j],f[i][j]);
}

surface s=surface(f,(0,0),(x.length-1,y.length-1),x.length-1,y.length-1);
real[] level=uniform(min(f)*(1-sqrtEpsilon),max(f)*(1+sqrtEpsilon),4);

s.colors(palette(s.map(new real(triple v) {return find(level >= v.z);}),
                 Rainbow())); 

draw(s,meshpen=thick());

triple m=currentpicture.userMin;
triple M=currentpicture.userMax;
triple target=0.5*(m+M);
currentprojection=perspective(camera=target+realmult(dir(68,225),M-m),
                              target=target);

xaxis3("$x$",Bounds,InTicks);
yaxis3("$y$",Bounds,InTicks(Step=1,step=0.1));
zaxis3("$z$",Bounds,InTicks);

Mots-clefs : , , , , ,


Official Asymptote example – gamma3

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 16 h 57 min

Figure 0082
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import palette;

size(12cm,IgnoreAspect);
currentprojection=orthographic(1,-2,1);

real X=4.5;
real M=abs(gamma((X,0)));

pair Gamma(pair z) 
{
  return (z.x > 0 || z != floor(z.x)) ? gamma(z) : M;
}

real f(pair z) {return min(abs(Gamma(z)),M);}

surface s=surface(f,(-2.1,-2),(X,2),70,Spline);

real Arg(triple v)
{
  return degrees(Gamma((v.x,v.y)),warn=false);
}

s.colors(palette(s.map(Arg),Wheel()));
draw(s);

xaxis3("$\mathop{\rm Re} z$",Bounds,InTicks);
yaxis3("$\mathop{\rm Im} z$",Bounds,InTicks(beginlabel=false));
zaxis3("$|\Gamma(z)|$",Bounds,InTicks);

Mots-clefs : , , , ,


Official Asymptote example – generalaxis3

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 18 h 57 min

Figure 0084
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

size(0,100);

path3 g=yscale3(2)*unitcircle3;
currentprojection=perspective(10,10,10);

axis(Label("C",position=0,align=15X),g,InTicks(endlabel=false,8,end=false),
     ticklocate(0,360,new real(real v) {
         path3 h=O--max(abs(max(g)),abs(min(g)))*dir(90,v);
         return intersect(g,h)[0];},
       new triple(real t) {return cross(dir(g,t),Z);}));


Mots-clefs : ,


Official Asymptote example – helix

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 23 h 57 min

Figure 0089
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

size(0,200);
size3(200,IgnoreAspect);

currentprojection=orthographic(4,6,3);

real x(real t) {return cos(2pi*t);}
real y(real t) {return sin(2pi*t);}
real z(real t) {return t;}

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

draw(p,Arrow3);

scale(true);

xaxis3(XZ()*"$x$",Bounds,red,InTicks(Label,2,2));
yaxis3(YZ()*"$y$",Bounds,red,InTicks(beginlabel=false,Label,2,2));
zaxis3(XZ()*"$z$",Bounds,red,InTicks);

Mots-clefs :


Official Asymptote example – impact

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 8 h 57 min

Figure 0098
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
// Contributed by Philippe Ivaldi.

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

Mots-clefs : , , , ,


Official Asymptote example – magnetic

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 17 h 57 min

Figure 0131
(Compiled with Asymptote version 1.87svn-r4652)
/* 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));

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

Mots-clefs : , , ,


Official Asymptote example – p-orbital

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 8 h 57 min

Figure 0146
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3; 
import palette; 
size(200); 
currentprojection=orthographic(6,8,2); 
 
real c0=0.1; 

real f(real r) {return r*(1-r/6)*exp(-r/3);}

triple f(pair t) {
  real r=t.x;
  real phi=t.y;
  real f=f(r);
  real s=max(min(c0/f,1),-1);
  real R=r*sqrt(1-s^2);
  return (R*cos(phi),R*sin(phi),r*s);
}

bool cond(pair t) {return f(t.x) != 0;}

real R=abs((20,20,20));
surface s=surface(f,(0,0),(R,2pi),100,8,Spline,cond);

s.colors(palette(s.map(abs),Gradient(palegreen,heavyblue))); 
draw(s); 
draw(zscale3(-1)*s); 
 
axes3("$x$","$y$","$z$",Arrow3);

Mots-clefs : , , , ,


Official Asymptote example – parametricelevation

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 9 h 57 min

Figure 0147
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import palette;
size(200);

currentprojection=orthographic(4,2,4);

triple f(pair z) {return expi(z.x,z.y);}

surface s=surface(f,(0,0),(pi,2pi),10,Spline);
draw(s,mean(palette(s.map(zpart),BWRainbow())),black,nolight);

Mots-clefs : , , ,


Official Asymptote example – parametricsurface

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 11 h 57 min

Figure 0149
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

size(200,0);
currentprojection=orthographic(4,0,2);

real R=2;
real a=1.9;

triple f(pair t) {
  return ((R+a*cos(t.y))*cos(t.x),(R+a*cos(t.y))*sin(t.x),a*sin(t.y));
}

pen p=rgb(0.2,0.5,0.7);

// surface only
draw(surface(f,(0,0),(2pi,2pi),8,8,Spline),lightgray);

// mesh only
//draw(surface(f,(0,0),(2pi,2pi),8,8,Spline),nullpen,meshpen=p);

// surface & mesh
//draw(surface(f,(0,0),(2pi,2pi),8,8,Spline),lightgray,meshpen=p);

Mots-clefs : , ,


Official Asymptote example – partialsurface

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 12 h 57 min

Figure 0150
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import palette;

size(0,300);
currentprojection=perspective(3,-2,2);

real V(real r) {return r^4-r^2;}
real V(pair pos) {return V(abs(pos));}

real R=1/sqrt(2);
real z=-0.2;

bool active(pair pos) {return abs(pos) < R;}
bool above(pair pos) {return V(pos) >= z;}

pair a=(-1.5,-1);
pair b=(0.5,1);
real f=1.2;

draw(plane(f*(b.x-a.x,0,z),(0,f*(b.y-a.y),z),(a.x,a.y,z)),
     lightgrey+opacity(0.5));

surface s=surface(V,a,b,40,Spline,active);
draw(s,mean(palette(s.map(new real(triple v) {
          return above((v.x,v.y)) ? 1 : 0;}),
      new pen[] {lightblue,lightgreen})),black);

xaxis3(Label("$\phi^\dagger\phi$",1),red,Arrow3);
zaxis3(Label("$V(\phi^\dagger\phi)$",1),0,0.3,red,Arrow3);

Mots-clefs : , , ,


Official Asymptote example – pathintersectsurface

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 13 h 57 min

Figure 0151
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
size(500);
import graph3;

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

Mots-clefs : , , ,


Official Asymptote example – pipeintersection

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 17 h 57 min

Figure 0155
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

currentprojection=orthographic(5,4,2);
currentlight=Headlamp;

size(12cm,0);

real f(pair z) {return min(sqrt(1-z.x^2),sqrt(1-z.y^2));}

surface s=surface(f,(0,0),(1,1),40,Spline);

transform3 t=rotate(90,O,Z), t2=t*t, t3=t2*t, i=xscale3(-1)*zscale3(-1);
draw(surface(s,t*s,t2*s,t3*s,i*s,i*t*s,i*t2*s,i*t3*s),blue);

Mots-clefs : , , ,


Official Asymptote example – planeproject

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 18 h 57 min

Figure 0156
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

size3(200,IgnoreAspect);

currentprojection=orthographic(4,6,3);

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

path3 p=graph(x,y,z,0,1,operator ..);

draw(p,Arrow3);
draw(planeproject(XY*unitsquare3)*p,red,Arrow3);
draw(planeproject(YZ*unitsquare3)*p,green,Arrow3);
draw(planeproject(ZX*unitsquare3)*p,blue,Arrow3);

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

Mots-clefs : ,


Official Asymptote example – projectelevation

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 23 h 57 min

Figure 0161
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import grid3;
import palette;

currentprojection=orthographic(0.8,1,2);

size(400,300,IgnoreAspect);

real f(pair z) {return cos(2*pi*z.x)*sin(2*pi*z.y);}

surface s=surface(f,(-1/2,-1/2),(1/2,1/2),50,Spline);

surface S=planeproject(unitsquare3)*s;
S.colors(palette(s.map(zpart),Rainbow()));
draw(S,nolight);
draw(s,lightgray+opacity(0.7));

grid3(XYZgrid);

Mots-clefs : , , , , , , , ,


Official Asymptote example – projectrevolution

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 0 h 57 min

Figure 0162
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import solids; 
import palette; 
 
currentprojection=orthographic(20,0,3); 
 
size(400,300,IgnoreAspect); 
 
revolution r=revolution(new real(real x) {return sin(x)*exp(-x/2);},
                          0,2pi,operator ..,Z); 
surface s=surface(r); 
 
surface S=planeproject(shift(-Z)*unitsquare3)*s;
S.colors(palette(s.map(zpart),Rainbow()));
draw(S);
draw(s,lightgray); 

Mots-clefs : , , , , , , ,


Official Asymptote example – roll

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 5 h 57 min

Figure 0167
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

size(200,0);

triple f(pair t) {
return(t.x+t.y/4+sin(t.y),cos(t.y),sin(t.y));
}

surface s=surface(f,(0,0),(2pi,2pi),7,20,Spline);
draw(s,olive);

Mots-clefs : , ,


Official Asymptote example – shellmethod

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 17 h 57 min

Figure 0179
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import solids;

size(400);
currentprojection=perspective(0,-1,30,up=Y);
currentlight=light(gray(0.75),(0.25,-0.25,1),(0,1,0));

pen color=green;
real alpha=240;

real f(real x) {return 2x^2-x^3;}
pair F(real x) {return (x,f(x));}
triple F3(real x) {return (x,f(x),0);}

int n=10;
path3[] blocks=new path3[n];
for(int i=1; i <= n; ++i) {
  real height=f((i-0.5)*2/n);
  real left=(i-1)*2/n;
  real right=i*2/n;
  blocks[i-1]=
    (left,0,0)--(left,height,0)--(right,height,0)--(right,0,0)--cycle;
}

path p=graph(F,0,2,n,operator ..)--cycle;
surface s=surface(p);
path3 p3=path3(p);

revolution a=revolution(p3,Y,0,alpha);
draw(surface(a),color);
draw(rotate(alpha,Y)*s,color);
for(int i=0; i < n; ++i)
  draw(surface(blocks[i]),color+opacity(0.5),black);
draw(p3);

xaxis3(Label("$x$",1,align=2X),Arrow3);
yaxis3(Label("$y$",1,align=2Y),ymax=1.4,dashed,Arrow3);
arrow("$y=2x^2-x^3$",XYplane(F(1.8)),X+Z,1.5cm,red,Arrow3(DefaultHead2));
draw(arc(1.17Y,0.3,90,0,7.5,180),ArcArrow3);

Mots-clefs : , , , ,


Official Asymptote example – shellsqrtx01

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 18 h 57 min

Figure 0180
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import solids;
size(0,150);
currentprojection=orthographic(1,0,10,up=Y);
pen color=green;
real alpha=-240;

real f(real x) {return sqrt(x);}
pair F(real x) {return (x,f(x));}
triple F3(real x) {return (x,f(x),0);}

path p=graph(F,0,1,n=30,operator ..)--(1,0)--cycle;
path3 p3=path3(p);

revolution a=revolution(p3,X,alpha,0);
draw(surface(a),color);
draw(p3,blue);

surface s=surface(p);
draw(s,color);
draw(rotate(alpha,X)*s,color);

xaxis3(Label("$x$",1),xmax=1.25,dashed,Arrow3);
yaxis3(Label("$y$",1),Arrow3);

dot("$(1,1)$",(1,1,0));
arrow("$y=\sqrt{x}$",F3(0.8),Y,0.75cm,red);

real r=0.4;
draw(F3(r)--(1,f(r),0),red);
real x=(1+r)/2;

draw("$r$",(x,0,0)--(x,f(r),0),X+0.2Z,red,Arrow3,PenMargin3);
draw(arc(1.1X,0.4,90,90,3,-90),Arrow3);

Mots-clefs : , , , ,


Official Asymptote example – sinc

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 20 h 57 min

Figure 0182
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import contour;

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

size(12cm,0);

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

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

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

Mots-clefs : , , , ,


Official Asymptote example – smoothelevation

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 23 h 57 min

Figure 0185
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import grid3;
import palette;

if(settings.render <= 0) settings.prc=false;

currentprojection=orthographic(1,2,13);

size(400,300,IgnoreAspect);

real f(pair z) {return cos(2*pi*z.x)*sin(2*pi*z.y);}

surface s=surface(f,(-1/2,-1/2),(1/2,1/2),20,Spline);
s.colors(palette(s.map(zpart),Rainbow()));

draw(s);

scale(true);

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

grid3(XYZgrid);

Mots-clefs : , , , ,


Official Asymptote example – soccerball

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 0 h 57 min

Figure 0186
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3; 
size(400); 
currentlight.background=palegreen;

real c=(1+sqrt(5))/2; 
 
triple[] z={(c,1,0),(-c,1,0),(-c,-1,0),(c,-1,0)}; 
triple[] x={(0,c,1),(0,-c,1),(0,-c,-1),(0,c,-1)}; 
triple[] y={(1,0,c),(1,0,-c),(-1,0,-c),(-1,0,c)}; 
 
triple[][] Q={
  {z[0],y[1],x[3],x[0],y[0],z[3]},
  {z[1],x[0],x[3],y[2],z[2],y[3]},
  {z[2],z[1],y[2],x[2],x[1],y[3]},
  {z[3],z[0],y[0],x[1],x[2],y[1]},
  {x[0],x[3],z[1],y[3],y[0],z[0]},
  {x[1],x[2],z[2],y[3],y[0],z[3]},
  {x[2],x[1],z[3],y[1],y[2],z[2]},
  {x[3],x[0],z[0],y[1],y[2],z[1]},
  {y[0],y[3],x[1],z[3],z[0],x[0]},
  {y[1],y[2],x[2],z[3],z[0],x[3]},
  {y[2],y[1],x[3],z[1],z[2],x[2]},
  {y[3],y[0],x[0],z[1],z[2],x[1]} 
}; 
 
path3 p=arc(O,Q[0][0],Q[0][1]); 
real R=abs(point(p,reltime(p,1/3))); 
 
triple[][] P;
for(int i=0; i < Q.length; ++i){
  P[i]=new triple[] ; 
  for(int j=0; j < Q[i].length; ++j){
    P[i][j]=Q[i][j]/R; 
  } 
} 
 
surface sphericaltriangle(triple center, triple A, triple B, triple C,
                          int nu=3, int nv=nu) {
  path3 tri1=arc(center,A,B); 
  path3 tri2=arc(center,A,C); 
  path3 tri3=arc(center,B,C); 
  triple tri(pair p) {
    path3 cr=arc(O,relpoint(tri2,p.x),relpoint(tri3,p.x)); 
    return relpoint(cr,p.y); 
  }; 
 
  return surface(tri,(0,0),(1-sqrtEpsilon,1),nu,nv,Spline); 
} 
 
for(int i=0; i < P.length; ++i){
  triple[] pentagon=sequence(new triple(int k) {
      path3 p=arc(O,P[i][0],P[i][k+1]); 
      return point(p,reltime(p,1/3)); 
    },5); 
  pentagon.cyclic=true; 
  draw(sequence(new path3(int k) {
        return arc(O,pentagon[k],pentagon[k+1]);},5),linewidth(2pt)); 
  triple M=unit(sum(pentagon)/5); 
  for(int i=0; i < 5; ++i){
    surface sf=sphericaltriangle(O,pentagon[i],M,pentagon[i+1]); 
    draw(sf,black); 
  } 
} 
 
for(int i=0; i < P.length; ++i){
  for(int j=1; j <= 5; ++j){
    triple K=P[i][0]; 
    triple A=P[i][j]; 
    triple B=P[i][(j % 5)+1]; 
    path3[] p={arc(O,K,A),arc(O,A,B),arc(O,B,K)}; 
    draw(subpath(p[0],reltime(p[0],1/3),reltime(p[0],2/3)),linewidth(4pt)); 
    triple[] hexagon={point(p[0],reltime(p[0],1/3)),
                      point(p[0],reltime(p[0],2/3)),
                      point(p[1],reltime(p[1],1/3)),
                      point(p[1],reltime(p[1],2/3)),
                      point(p[2],reltime(p[2],1/3)),
                      point(p[2],reltime(p[2],2/3))}; 
    hexagon.cyclic=true; 
    triple M=unit(sum(hexagon)/6); 
    for(int i=0; i < 6; ++i){
      surface sf=sphericaltriangle(O,hexagon[i],M,hexagon[i+1]); 
      draw(sf,white); 
    } 
  } 
}

Mots-clefs : , , , , , ,


Official Asymptote example – sphericalharmonic

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 5 h 57 min

Figure 0191
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import palette;
size(200);

currentprojection=orthographic(4,2,4);

real r(real theta, real phi) {return 1+0.5*(sin(2*theta)*sin(2*phi))^2;}

triple f(pair z) {return r(z.x,z.y)*expi(z.x,z.y);}

surface s=surface(f,(0,0),(pi,2pi),50,Spline);
s.colors(palette(s.map(abs),Gradient(yellow,red)));
draw(s);

Mots-clefs : , , ,


Official Asymptote example – spiral3

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 7 h 57 min

Figure 0193
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import palette;
 
size3(10cm);
 
currentprojection=orthographic(5,4,2);

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);
draw(T.center,thin());

Mots-clefs : , , , , ,


Official Asymptote example – sqrtx01

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 12 h 57 min

Figure 0198
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import solids;
size(0,150);
currentprojection=perspective(1.5,0,10,Y);
pen color=green+opacity(0.75);

real f(real x){return sqrt(x);}
pair F(real x){return (x,f(x));}
triple F3(real x){return (x,f(x),0);}

path p=graph(F,0,1,n=20,operator ..);
path3 p3=path3(p);

revolution a=revolution(p3,X,0,360);
draw(surface(a),color);
draw(p3,blue);

real x=relpoint(p,0.5).x;

xaxis3(Label("$x$",1),xmax=1.5,dashed,Arrow3);
yaxis3(Label("$y$",1),Arrow3);
dot(Label("$(1,1)$"),(1,1,0));
arrow(Label("$y=\sqrt{x}$"),F3(0.7),Y,0.75cm,red);
draw(arc(1.2X,0.4,90,90,175,-40,CW),Arrow3);
draw("$r$",(x,0,0)--F3(x),red,Arrow3,PenMargin3);

Mots-clefs : , , , ,


Official Asymptote example – sqrtx01y1

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 13 h 57 min

Figure 0199
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import solids;
size(0,150);
currentprojection=perspective(0,1,10,up=Y);

real f(real x) {return sqrt(x);}
pair F(real x) {return (x,f(x));}
triple F3(real x) {return (x,f(x),0);}

path p=graph(F,0,1,n=25,operator ..);
path3 p3=path3(p);

revolution a=revolution(p3,Y,0,360);
draw(surface(a),green);
draw(p3,blue);

xtick((0,0,0));
xtick((1,0,0));

xaxis3(Label("$x$",1),Arrow3);
yaxis3(Label("$y$",1),ymax=1.5,dashed,Arrow3);
dot(Label("$(1,1)$"),(1,1,0));
arrow("$y=\sqrt{x}$",F3(0.5),X,0.75cm,red);
draw(arc(1.2Y,0.3,90,0,7.5,140),Arrow3);

Mots-clefs : , , , ,


Official Asymptote example – torus

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 3 h 57 min

Figure 0213
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
size(200);
import graph3;

currentprojection=perspective(5,4,4);

//import solids;
//revolution torus=revolution(shift(3X)*Circle(O,1,Y,32),Z,90,345);
//draw(surface(torus),green);

real R=3;
real a=1;

triple f(pair t) {
  return ((R+a*cos(t.y))*cos(t.x),(R+a*cos(t.y))*sin(t.x),a*sin(t.y));
}

draw(surface(f,(radians(90),0),(radians(345),2pi),8,8,Spline),green);

Mots-clefs : ,


Official Asymptote example – trefoilknot

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 6 h 57 min

Figure 0216
(Compiled with Asymptote version 1.87svn-r4652)
/* 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;

pen[] pens=Gradient(6,red,blue,purple);
pens.push(yellow);
for (int i=pens.length-2; i >= 0 ; --i)
  pens.push(pens[i]);

path sec=scale(0.25)*texpath("$\pi$")[0];
coloredpath colorsec=coloredpath(sec, pens,colortype=coloredNodes);
draw(tube(p,colorsec));

Mots-clefs : , , , ,


Official Asymptote example – trumpet

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 10 h 57 min

Figure 0220
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
size(200,0);

triple f(pair t) {
  return(10*sin(t.y),cos(t.x)*(cos(t.y)+log(abs(tan(t.y/2)))),
         sin(t.x)*(cos(t.y)+log(abs(tan(t.y/2)))));
}

surface s=surface(f,(0,pi/2),(2pi,pi-0.1),7,15,Spline);
draw(s,olive);

Mots-clefs : , ,


Official Asymptote example – twistedtubes

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 12 h 57 min

Figure 0222
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;  
import palette; 
 
size(300,300,keepAspect=true);  
 
real w=0.4;

real f(triple t) {return sin(t.x);} 
triple f1(pair t) {return (cos(t.x)-2cos(w*t.y),sin(t.x)-2sin(w*t.y),t.y);}
triple f2(pair t) {return (cos(t.x)+2cos(w*t.y),sin(t.x)+2sin(w*t.y),t.y);}
triple f3(pair t) {return (cos(t.x)+2sin(w*t.y),sin(t.x)-2cos(w*t.y),t.y);}
triple f4(pair t) {return (cos(t.x)-2sin(w*t.y),sin(t.x)+2cos(w*t.y),t.y);}

surface s1=surface(f1,(0,0),(2pi,10),8,8,Spline); 
surface s2=surface(f2,(0,0),(2pi,10),8,8,Spline); 
surface s3=surface(f3,(0,0),(2pi,10),8,8,Spline); 
surface s4=surface(f4,(0,0),(2pi,10),8,8,Spline); 

pen[] Rainbow=Rainbow();
s1.colors(palette(s1.map(f),Rainbow)); 
s2.colors(palette(s2.map(f),Rainbow)); 
s3.colors(palette(s3.map(f),Rainbow)); 
s4.colors(palette(s4.map(f),Rainbow)); 

draw(s1); 
draw(s2);
draw(s3);
draw(s4);

Mots-clefs : , ,


Official Asymptote example – vectorfield3

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 18 h 57 min

Figure 0228
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

size(12cm,0);

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

real f(pair z) {return abs(z)^2;}

path3 gradient(pair z) {
  static real dx=sqrtEpsilon, dy=dx;
  return O--((f(z+dx)-f(z-dx))/2dx,(f(z+I*dy)-f(z-I*dy))/2dy,0);
}

pair a=(-1,-1);
pair b=(1,1);

triple F(pair z) {return (z.x,z.y,0);}

add(vectorfield(gradient,F,a,b,red));

draw(surface(f,a,b,Spline),gray+opacity(0.5));

xaxis3(XY()*"$x$",OutTicks(XY()*Label));
yaxis3(XY()*"$y$",InTicks(YX()*Label));
zaxis3("$z$",OutTicks);

Mots-clefs : ,


Official Asymptote example – vectorfieldsphere

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 19 h 57 min

Figure 0229
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;

size(12cm);

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

triple f(pair z) {return expi(z.x,z.y);}

path3 vector(pair z) {
  triple v=f(z);
  return O--(v.y,v.z,v.x);
}

add(vectorfield(vector,f,(0,0),(pi,2pi),10,0.25,red));

draw(unitsphere,gray+opacity(0.5));

Mots-clefs : , , ,


Official Asymptote example – washermethod

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 22 h 57 min

Figure 0232
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import solids;
size(0,150);
currentprojection=perspective(0,0,11,up=Y);

pen color1=green+opacity(0.25);
pen color2=red;
real alpha=250;

real f(real x) {return 2x^2-x^3;}
pair F(real x) {return (x,f(x));}
triple F3(real x) {return (x,f(x),0);}

ngraph=12;
path[] p={graph(F,0.7476,1.8043,Spline)--cycle,
          graph(F,0.7,0.7476,Spline)--graph(F,1.7787,1.8043,Spline)--cycle,
          graph(F,0,0.7,Spline)--graph(F,1.8043,2,Spline)--cycle};

pen[] pn=new pen[] {color1,color2,color1};

for(int i=0; i < p.length; ++i) {
  revolution a=revolution(path3(p[i]),Y,0,alpha);
  draw(surface(a),pn[i]);

  surface s=surface(p[i]);
  draw(s,pn[i]);
  draw(rotate(alpha,Y)*s,pn[i]);
}

draw((4/3,0,0)--F3(4/3),dashed);
xtick("$\frac{4}{3}$",(4/3,0,0));

xaxis3(Label("$x$",1),Arrow3);
yaxis3(Label("$y$",1),ymax=1.25,dashed,Arrow3);
arrow("$y=2x^2-x^3$",F3(1.6),X+Y,0.75cm,red);
draw(arc(1.1Y,0.3,90,0,7.5,180),Arrow3);

Mots-clefs : , , , ,


Official Asymptote example – wedge

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 23 h 57 min

Figure 0233
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import solids;
size(0,150);
currentprojection=perspective(8,10,2);
currentlight=White;

draw(circle(O,4,Z));
draw(shift(-4Z)*scale(4,4,8)*unitcylinder,green+opacity(0.2));

triple F(real x){return (x,sqrt(16-x^2),sqrt((16-x^2)/3));}
path3 p=graph(F,0,4,operator ..);
path3 q=reverse(p)--rotate(180,(0,4,4/sqrt(3)))*p--cycle;
draw(surface(q--cycle),red);

real t=2;
path3 triangle=(t,0,0)--(t,sqrt(16-t^2),0)--F(t)--cycle;
draw(surface(triangle),blue);

xaxis3("$x$",Arrow3,PenMargin3(0,0.25));
yaxis3("$y$",Arrow3,PenMargin3(0,0.25));
zaxis3("$z$",dashed,Arrow3);

Mots-clefs : , , , ,


Official Asymptote example – xxsq01

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 3 h 57 min

Figure 0237
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import solids;
size(0,150);
currentprojection=perspective(0,0,10,up=Y);

pen color=green;
real alpha=250;

real f(real x) {return x^2;}
pair F(real x) {return (x,f(x));}
triple F3(real x) {return (x,f(x),0);}

path p=graph(F,0,1,n=10,operator ..)--cycle;
path3 p3=path3(p);

revolution a=revolution(p3,X,-alpha,0);
draw(surface(a),color);

surface s=surface(p);
draw(s,color);
draw(rotate(-alpha,X)*s,color);

draw(p3,blue);

xaxis3(Label("$x$",1),xmax=1.25,dashed,Arrow3);
yaxis3(Label("$y$",1),Arrow3);
dot(Label("$(1,1)$"),(1,1,0),X+Y);
arrow("$y=x$",(0.7,0.7,0),Y,0.75cm,red);
arrow("$y=x^2$",F3(0.7),X,0.75cm,red);
draw(arc(1.1X,0.3,90,90,3,-90),Arrow3);

Mots-clefs : , , , ,


Official Asymptote example – xxsq01x-1

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 4 h 57 min

Figure 0238
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import solids;
size(300);
currentprojection=perspective(0,2,10,up=Y);
currentlight=(0.25,-0.25,5);

pen color=green;

real f(real x) {return x^2;}
pair F(real x) {return (x,f(x));}
triple F3(real x) {return (x,f(x),0);}

path p=graph(F,0,1,n=10,operator ..)--cycle;
path3 p3=path3(p);

revolution a=revolution(-X,p3,Y,0,180);
draw(surface(a),color);
surface s=surface(p);
draw(s,color);
transform3 t=shift(-2X)*rotate(180,Y);
draw(t*s,color);
draw(p3);
draw(t*p3);

draw((-1,0,0)--(-1,1,0),dashed);
xaxis3(Label("$x$",1),Arrow3);
yaxis3(Label("$y$",1),Arrow3);
dot(Label("$(1,1)$"),(1,1,0));
dot(Label("$(-1,1)$"),(-1,1,0),W);
arrow("$y=x^{2}$",F3(0.7),X,1cm,red); 
arrow("$y=x$",(0.3,0.3,0),X,1.5cm,red); 
draw(circle((-1,1,0),2,Y),dashed);
draw((-1,1,0)--(1,1,0),dashed);
draw(shift(-X)*arc(0.02Y,0.3,90,0,0,0,CW),Arrow3);

Mots-clefs : , , , ,


Official Asymptote example – xxsq01y

Catégorie : Asymptote, Official Gallery One-PagerPh. Ivaldi @ 5 h 57 min

Figure 0239
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import solids;
size(0,150);
currentprojection=perspective(0,0,10,up=Y);
pen color=green;
real alpha=240;

real f(real x) {return x^2;}
pair F(real x) {return (x,f(x));}
triple F3(real x) {return (x,f(x),0);}

path p=graph(F,0,1,n=10,operator ..)--cycle;
path3 p3=path3(p);

draw(surface(revolution(p3,Y,0,alpha)),color);

surface s=surface(p);
draw(s,color);
draw(rotate(alpha,Y)*s,color);

draw(p3,blue);

xaxis3(Label("$x$",1),Arrow3);
yaxis3(Label("$y$",1),ymax=1.25,dashed,Arrow3);

dot("$(1,1)$",(1,1,0),X);
arrow("$y=x^{2}$",F3(0.7),X,0.75cm,red); 
arrow("$y=x$",(0.8,0.8,0),Y,1cm,red); 

real r=0.4;
draw((r,f(r),0)--(r,r,0),red);
draw("$r$",(0,(f(r)+r)*0.5,0)--(r,(f(r)+r)*0.5,0),N,red,Arrows3,PenMargins3);
draw(arc(1.1Y,0.3,90,0,7.5,180),Arrow3);

Mots-clefs : , , , ,


Animation with Asymptote – fig0080

Catégorie : Animation, AsymptotePh. Ivaldi @ 15 h 20 min

Figure 0008
(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);
  A.add();
  restore();
}

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

Mots-clefs : , , , , , ,


Animation with Asymptote – fig0090

Catégorie : Animation, AsymptotePh. Ivaldi @ 16 h 20 min

Figure 0009
(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);

  A.add();
  restore();
}

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

Mots-clefs : , , , , , , , ,