Surfaces à la TES

Règles du forum
ATTENTION ! Il est demandé de ne déposer dans ce forum que des exemples en langage Asymptote
  • finalisés
  • que l'on pense intéressants et optimisés
  • et qui se rapportent au thème du forum.
Si certains exemples déposés donnent lieu à de nombreuses modifications, ils seront déplacés et remplacés par un nouveau sujet dans ce forum avec la ou les meilleures propositions.
Pour les demandes d'aide ... il y a un forum spécifique !
maurice
Messages : 262
Enregistré le : jeu. 25 mars 2010, 13:00
Contact :

Surfaces à la TES

Message non lu par maurice » sam. 14 juil. 2012, 16:16

Bonjour,

Première contribution après deux années passées sur ce forum et qui n'est pas vraiment personnelle puisqu'on en avait parlé , et . En hommage aux surfaces type "bac ES".

Code : Tout sélectionner

import grid3;
import palette;
import contour;
currentprojection=orthographic(-3,-3,1);
size3(7cm,7cm,7cm,IgnoreAspect);

real xmin=0,
     ymin=0,
     zmin=0,
     xmax=10,
     ymax=10,
     zmax=6;

limits((xmin,ymin,zmin),(xmax,ymax,zmax));

real Dx=1, Dy=1, Dz=1;
real Nb=zmax/Dz;


// Définition de la fonction
real f(pair z) {return log(2*z.x^2+z.y^2+1);}
surface s=surface(f, (xmin,ymin), (xmax,ymax), nx=150, ny=150, Spline);


// Couleurs ; Lignes de niveau
pen[] pal=Rainbow();

real[] lignesdeniveau;
for (int i=1; i<=Nb; ++i) {real ligne=Dz*i ;
           lignesdeniveau.push(ligne);
}

s.colors(palette(s.map(new real(triple v) {return find(lignesdeniveau > v.z);}),pal));
draw(s);

draw(lift(f,contour(f,(xmin,ymin),(xmax,ymax),lignesdeniveau)),1.5bp+blue);

for (int i=1; i<= xmax/Dx; ++i) {
   real x1(real t) {return i*Dx;}
   real y1(real t) {return t;}
   real z1(real t) {pair z=(i*Dx,t); return f(z);}
   path3 lx=graph(x1,y1,z1,ymin,ymax);
   draw(lx, black);
}

for (int i=1; i<= ymax/Dy; ++i) {
   real x1(real t) {return t;}
   real y1(real t) {return i*Dy;}
   real z1(real t) {pair z=(t,i*Dy); return f(z);}
   path3 lx=graph(x1,y1,z1,xmin,xmax);
   draw(lx, black);
}


// Axes et grilles
grid3(XYgrid, Step=Dx);
grid3(YXgrid, Step=Dy);
grid3(ZXgrid(Relative(1)), Step=Dz);
grid3(YZgrid(Relative(1)), Step=Dy);
grid3(XZgrid(Relative(1)), Step=Dx);
grid3(ZYgrid(Relative(1)), Step=Dz);

xaxis3(Label("$x$",MidPoint,align=-Z),
Bounds(Both,Min),OutTicks(Step=Dx,endlabel=true),p=blue);
yaxis3(Label("$y$",MidPoint,align=-Z),
Bounds(Both,Min),OutTicks(Step=Dy, step=0),p=red);
zaxis3(Label("$z$" ,MidPoint,align=-X),XYEquals(xmin,ymax),InTicks(Step=Dz, step=0,Label(align=Y)),p=1bp+.5green);


log.png
log.png (156.42 Kio) Vu 7744 fois
Doc 3D
Si ça ne marche pas, essayez la version pdf

Fedora 23 -- Asymptote 2.35 -- TeXlive 2013 -- emacs et/ou gedit

maurice
Messages : 262
Enregistré le : jeu. 25 mars 2010, 13:00
Contact :

Re: Surfaces à la TES

Message non lu par maurice » sam. 14 juil. 2012, 16:17

On avait eu plus de difficultés pour les projections des lignes de niveau. Mais en s'inpirant d'un code de Philippe Ivaldi, je propose ça :


Code : Tout sélectionner

import graph;
import palette;
import contour;

unitsize(1cm);

real xmin=0,
     ymin=0,
     zmin=0,
     xmax=10,
     ymax=10,
     zmax=6;

pair a=(xmin,ymin), b=(xmax,ymax);

real f(real x, real y) {return log(2*x^2+y^2+1);}

int N=200;
int Divs=floor(zmax-zmin);

defaultpen(1.5bp);


// couleurs

pen[] Palette=quantize(Rainbow(),Divs);

pen pinceau(real x, real y) {
  int color=floor(f(x,y));
  return Palette[color];
}


// Projection de la surface

real x=xmin, y=ymin;
real step=0.025;
int xloop=round((xmax-xmin)/step);
int yloop=round((ymax-ymin)/step);
path sq=scale(step)*unitsquare;

for(int i=1; i < xloop; ++i) {
  for(int j=0; j < yloop; ++j) {
    pen p=pinceau(x,y);
    filldraw(shift(x,y)*sq, p, p);
    y+=step;
  }
  x+=step;
  y=ymin;
}


//lignes de niveau
bounds range=bounds(zmin, zmax);
real[] Cvals=uniform(range.min,range.max,Divs);
guide[][] g=contour(f,a,b,Cvals,N,operator --);
draw(g);


// Axes
pen Tickpen=.3bp+gray+linetype("4 4");
// pen tickpen=gray+0.5*linewidth(currentpen);

xaxis("$x$",BottomTop,LeftTicks(extend=true, Step=1, step=0, Tickpen), above=true);
yaxis("$y$",LeftRight,RightTicks(extend=true, Step=1, step=0, Tickpen),above=true);


// Palette
palette("$f(x,y) = \ln(2x^2+y^2+1)$",range,(11,ymin),(12,ymax),Right,Palette,
   PaletteTicks(n=1)
   );


log-lignes.png
log-lignes.png (74.62 Kio) Vu 7743 fois


Ces codes s'adaptent facilement à d'autres fonctions. Si ça intéresse, j'en ai un gros stock en réserve.

Bruno
Doc 3D
Si ça ne marche pas, essayez la version pdf

Fedora 23 -- Asymptote 2.35 -- TeXlive 2013 -- emacs et/ou gedit

Répondre