Asymptote using graph3.asy – fig0110

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

Figure 0011
(Compiled with Asymptote version 2.14svn-r5318)
    
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-clés : , , , , , , , , , ,


Asymptote using graph3.asy – fig0120

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

Figure 0012
(Compiled with Asymptote version 2.14svn-r5318)
    
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-clés : , , , , ,


Asymptote using graph3.asy – fig0130

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

Figure 0013
(Compiled with Asymptote version 2.14svn-r5318)
    
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-clés : , , ,


Asymptote using graph3.asy – fig0140

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

Figure 0014
(Compiled with Asymptote version 2.14svn-r5318)
    
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-clés : , , ,


Asymptote using graph3.asy – fig0150

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

Figure 0015
(Compiled with Asymptote version 2.14svn-r5318)
    
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-clés : , , , , ,


Asymptote using graph3.asy – fig0160

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

Figure 0016
(Compiled with Asymptote version 2.14svn-r5318)
    
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-clés : , , , , ,


Asymptote using graph3.asy – fig0170

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

Figure 0017
(Compiled with Asymptote version 2.14svn-r5318)
    
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-clés : , , , , ,


Asymptote using graph3.asy – fig0180

Category: 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 2.14svn-r5318)
    
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-clés : , , , , ,


Asymptote using three.asy – fig0020

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

Figure 0002
(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),Gradient(yellow,red)));
// 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)));

Mots-clés : , , , , ,


Asymptote using three.asy – fig0030

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

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

Mots-clés : , , , , ,


Asymptote using solids.asy – fig0080

Category: Asymptote,Examples 3D,solids.asyPh. Ivaldi @ 9 h 56 min

Figure 0008
(Compiled with Asymptote version 2.14svn-r5318)
    
import solids;
import palette;
size(14cm,0);
currentlight=light(gray(0.4),specularfactor=3,viewport=false,
                   (-0.5,-0.25,0.45),
                   (0.5,-0.5,0.5),(0.5,0.5,0.75));

nslice=4*nslice;
surface s=surface(sphere(O,1));
draw(s,lightgrey);

path3 pl=plane((1,0,0),(0,1,0),(0,0,-1));
surface pls=shift(3,3,-1e-3)*scale(-6,-6,1)*surface(pl);
draw(pls,0.7*red);

real dist(triple z){return abs(z-Z);}

surface shade;
for (int i=0; i < currentlight.position.length; ++i) {
  shade=planeproject(pl,currentlight.position[i])*s;
  draw(shade,mean(palette((shade.map(dist)),
                          Gradient(black,gray(0.6)))),
       nolight);
}

Mots-clés : , , , , , ,


Asymptote using tube.asy – fig0050

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

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

Mots-clés : , ,


Asymptote using tube.asy – fig0060

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

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

Mots-clés : , ,


Asymptote using tube.asy – fig0070

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

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

Mots-clés : , ,


Asymptote using tube.asy – fig0080

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

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

Mots-clés : , ,


Asymptote using tube.asy – fig0090

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

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

Mots-clés : , , ,


Asymptote using tube.asy – fig0120

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

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

Mots-clés : ,


Asymptote using tube.asy – fig0210

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

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

Mots-clés : , , ,


Official Asymptote example – RiemannSurface

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

Figure 0182
(Compiled with Asymptote version 2.14svn-r5318)
/* 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,render(merge=true));

Mots-clés : , , , ,


Official Asymptote example – RiemannSurfaceRoot

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

Figure 0183
(Compiled with Asymptote version 2.14svn-r5318)
/* 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);
 
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,render(merge=true));

Mots-clés : , , ,


Official Asymptote example – cheese

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

Figure 0024
(Compiled with Asymptote version 2.14svn-r5318)
/* 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,render(merge=true));

Mots-clés : , , , , ,


Official Asymptote example – condor

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

Figure 0031
(Compiled with Asymptote version 2.14svn-r5318)
/* 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,render(compression=Low,merge=true));

Mots-clés : , , , ,


Official Asymptote example – elevation

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

Figure 0053
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import grid3;
import palette;

currentprojection=orthographic(0.8,1,1);

size(400,300,IgnoreAspect);

defaultrender.merge=true;

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-clés : , , , ,


Official Asymptote example – extrudedcontour

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

Figure 0061
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import contour;
import palette;
import graph3;

defaultrender.merge=true;

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

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

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

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


Mots-clés : , , , ,


Official Asymptote example – fin

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

Figure 0067
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import three;
import palette;

int N = 26;
real[] C = array(N,0); 
real[][] A = new real[N][N];
for(int i = 0; i < N; ++i)
  for(int j = 0; j < N; ++j)
    A[i][j] = 0;

real Tb = 100; // deg C
real h = 240; // 240 W/m^2 K
real k = 240; // W/m K
real Tinf = 20; // deg C
real L = 12; // cm
real t = 2; // cm

real delta = 0.01; // 1 cm = 0.01 m

// (1,2)-(2,2)-(3,2)-...-(13,2)
//   |     |     |          |
// (1,1)-(2,1)-(3,1)-...-(13,1)
//
//        |
//       \ /
//        V
//
// 13-14-15-...-24-25
//  |  |  | ...  |  |
//  0- 1- 2-...-11-12

// but, note zero-based array indexing, so counting starts at 0
int indexof(int m, int n)
{
  return 13(n-1)+m-1;
}

int i = 0;

// fixed temperature bottom left
A[i][indexof(1,1)] = 1; C[i] = Tb;
++i;
// fixed temperature middle left
A[i][indexof(1,2)] = 1; C[i] = Tb;
++i;

// interior nodes
for(int m = 2; m<13; ++m)
{
  A[i][indexof(m,2)] = -4;
  A[i][indexof(m-1,2)] = A[i][indexof(m+1,2)] = 1;
  A[i][indexof(m,1)] = 2;
  C[i] = 0;
  ++i;
}

// convective bottom side nodes
for(int m = 2; m<13; ++m)
{
  A[i][indexof(m,1)] = -(2+h*delta/k);
  A[i][indexof(m-1,1)] = A[i][indexof(m+1,1)] = 0.5;
  A[i][indexof(m,2)] = 1;
  C[i] = -h*delta*Tinf/k;
  ++i;
}

// convective bottom right corner node
A[i][indexof(13,2)] = A[i][indexof(12,1)] = 0.5;
A[i][indexof(13,1)] = -(1+h*delta/k);
C[i] = -h*delta*Tinf/k;
++i;

// convective middle right side node
A[i][indexof(13,2)] = -(2+h*delta/k);
A[i][indexof(13,1)] = 1;
A[i][indexof(12,2)] = 1;
C[i] = -h*delta*Tinf/k;
++i;

real[] T = solve(A,C);

pen[] Palette = Gradient(256,blue,cyan,yellow,orange,red);

real[][] T = {T[0:13],T[13:26],T[0:13]};
T = transpose(T);

size3(15cm);
real w = 10;
real h = 5;
currentprojection = orthographic(2*(L,h,w),Y);
draw((L,t,0)--(L,0,0)--(L,0,w)--(0,0,w)--(0,-h,w));
draw((0,t,w)--(0,t+h,w)--(0,t+h,0)--(0,t,0));
draw((L,0,w)--(L,t,w)--(0,t,w)--(0,t,0)--(L,t,0)--(L,t,w));

real wo2 = 0.5*w;
draw((0,0,wo2)--(0,t,wo2)--(L,t,wo2)--(L,0,wo2)--cycle);

// centre points
surface square = surface(shift(-0.5,-0.5,wo2)*unitsquare3);
surface bottomsquare = surface(shift(-0.5,-0.5,wo2)*scale(1,0.5,1)*unitsquare3);
surface topsquare = surface(shift(-0.5,0,wo2)*scale(1,0.5,1)*unitsquare3);
surface leftsquare = surface(shift(-0.5,-0.5,wo2)*scale(0.5,1,1)*unitsquare3);
surface rightsquare = surface(shift(0,-0.5,wo2)*scale(0.5,1,1)*unitsquare3);
surface NEcorner = surface(shift(0,0,wo2)*scale(0.5,0.5,1)*unitsquare3);
surface SEcorner = surface(shift(0,-0.5,wo2)*scale(0.5,0.5,1)*unitsquare3);
surface SWcorner = surface(shift(-0.5,-0.5,wo2)*scale(0.5,0.5,1)*unitsquare3);
surface NWcorner = surface(shift(-0.5,0,wo2)*scale(0.5,0.5,1)*unitsquare3);

material lookupColour(int m,int n)
{
  int index = round(Palette.length*(T[m-1][n-1]-60)/(100-60));
  if(index >= Palette.length) index = Palette.length-1;
  return emissive(Palette[index]);
}

draw(shift(0,1,0)*rightsquare,lookupColour(1,2));
for(int i = 2; i < 13; ++i)
{
  draw(shift(i-1,1,0)*square,lookupColour(i,2));
}
draw(shift(12,1,0)*leftsquare,lookupColour(13,2));

draw(shift(0,2,0)*SEcorner,lookupColour(1,3));
draw(shift(0,0,0)*NEcorner,lookupColour(1,1));
for(int i = 2; i < 13; ++i)
{
  draw(shift(i-1,0,0)*topsquare,lookupColour(i,1));
  draw(shift(i-1,2,0)*bottomsquare,lookupColour(i,3));
}
draw(shift(12,2,0)*SWcorner,lookupColour(13,3));
draw(shift(12,0,0)*NWcorner,lookupColour(13,1));

// annotations
draw("$x$",(0,-h/2,w)--(L/4,-h/2,w),Y,Arrow3(HookHead2(normal=Z)),BeginBar3(Y));
draw("$y$",(0,0,1.05*w)--(0,2t,1.05*w),Z,Arrow3(HookHead2(normal=X)),
     BeginBar3(Z));
draw("$z$",(L,-h/2,0)--(L,-h/2,w/4),Y,Arrow3(HookHead2(normal=X)),BeginBar3(Y));

draw("$L$",(0,-h/4,w)--(L,-h/4,w),-Y,Arrows3(HookHead2(normal=Z)),
     Bars3(Y),PenMargins2);
draw("$w$",(L,-h/4,0)--(L,-h/4,w),-Y,Arrows3(HookHead2(normal=X)),
     Bars3(Y),PenMargins2);
draw("$t$",(1.05*L,0,0)--(1.05*L,t,0),-2Z,Arrows3(HookHead2(normal=Z)),
     Bars3(X),PenMargins2);

label(ZY()*"$T_b$",(0,t+h/2,wo2));

label("$h$,$T_\infty$",(L/2,t+h/2,0),Y);
path3 air = (L/2,t+h/3,w/3.5)--(1.5*L/2,t+2*h/3,w/8);
draw(air,EndArrow3(TeXHead2));
draw(shift(0.5,0,0)*air,EndArrow3(TeXHead2));
draw(shift(1.0,0,0)*air,EndArrow3(TeXHead2));

Mots-clés : , , ,


Official Asymptote example – gamma3

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

Figure 0076
(Compiled with Asymptote version 2.14svn-r5318)
/* 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,render(compression=Low,merge=true));

real xmin=point((-1,-1,-1)).x;
real xmax=point((1,1,1)).x;
draw((xmin,0,0)--(xmax,0,0),dashed);

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

Mots-clés : , , , ,


Official Asymptote example – p-orbital

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

Figure 0172
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import palette;
size(200);
currentprojection=orthographic(6,8,2);
viewportmargin=(1cm,0);
 
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)));

render render=render(compression=Low,merge=true);
draw(s,render);
draw(zscale3(-1)*s);
 
axes3("$x$","$y$","$z$",Arrow3);

Mots-clés : , , , ,


Official Asymptote example – parametricelevation

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

Figure 0155
(Compiled with Asymptote version 2.14svn-r5318)
/* 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,render(merge=true));

Mots-clés : , , ,


Official Asymptote example – partialsurface

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

Figure 0158
(Compiled with Asymptote version 2.14svn-r5318)
/* 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-clés : , , ,


Official Asymptote example – projectelevation

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

Figure 0174
(Compiled with Asymptote version 2.14svn-r5318)
/* 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-clés : , , , , , , , ,


Official Asymptote example – projectrevolution

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

Figure 0175
(Compiled with Asymptote version 2.14svn-r5318)
/* 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()));

render render=render(compression=Low,merge=true);
draw(S,render);
draw(s,lightgray,render); 

Mots-clés : , , , , , , ,


Official Asymptote example – smoothelevation

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

Figure 0207
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import grid3;
import palette;

currentlight=Viewport;

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-clés : , , , ,


Official Asymptote example – sphericalharmonic

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

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

currentprojection=orthographic(4,2,4);
currentlight=Viewport;

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,render(compression=Low,merge=true));

Mots-clés : , , ,


Official Asymptote example – spiral3

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

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

Mots-clés : , , , , ,


Official Asymptote example – trefoilknot

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

Figure 0239
(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;

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),render(merge=true));

Mots-clés : , , , ,


Official Asymptote example – twistedtubes

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

Figure 0246
(Compiled with Asymptote version 2.14svn-r5318)
/* 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)); 

defaultrender.merge=true;

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

Mots-clés : , ,


Official Asymptote example – vertexshading

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

Figure 0256
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import three;

size(200);

currentprojection=perspective(4,5,5);

draw(surface(unitcircle3,new pen[] {red,green,blue,white}));
draw(surface(shift(Z)*unitsquare3,
             new pen[] {red,green+opacity(0.5),blue,black}));

Mots-clés : , ,