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

Étiquettes : , , , , , , , , , ,


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

Étiquettes : , , , , ,


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

Étiquettes : , , ,


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

Étiquettes : , , ,


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

Étiquettes : , , , , ,


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

Étiquettes : , , , , ,


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

Étiquettes : , , , , ,


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

Étiquettes : , , , , ,


Asymptote using grid3.asy – fig0100

Category: Asymptote,Examples 3D,grid3.asyPh. Ivaldi @ 20 h 09 min

Figure 0001
(Compiled with Asymptote version 2.14svn-r5318)
    
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)
      above=false         // bool (default=false)
      );

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

Étiquettes : , ,


Asymptote using grid3.asy – fig0200

Category: Asymptote,Examples 3D,grid3.asyPh. Ivaldi @ 21 h 09 min

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

Étiquettes : , ,