PIPRIME.FR BLOG

Live fully to honor life

Animations with the Asymptote drawing software

Animation produced with the Asymptote drawing and programming software

🔗animations-fig001

Show animations/fig0010.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Animation | #Contour | #Surface | #Function (implicit)

import contour3;
import animate;
// settings.tex="pdflatex";
// settings.outformat="pdf";

size(10cm);
currentprojection=orthographic(15,8,10);
animation A;
A.global=false;

typedef real fct3(real,real,real);
fct3 F(real t)
{
  return new real(real x, real y, real z){return x^2+y^2-t*z^2+t-1;};
}

int n=10;
picture pic;
real tmin=0.1, tmax=2;
real step=(tmax-tmin)/n;
draw(box((-5,-5,-5),(5,5,5)));
for (int i=0; i < n; ++i) {
  save();
  draw(surface(contour3(F(tmin+i*step),(-5,-5,-5),(5,5,5),15)),lightblue);
  pic.erase();
  add(pic,bbox(5mm,FillDraw(lightyellow)));
  A.add(pic);
  restore();
}

A.movie();

🔗animations-fig002

Show animations/fig0020.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Animation | #Geometry | #Circle

import geometry;
import animate;
settings.tex = "pdflatex";

animation A;
size(12cm);

for (int a = 1; a < 20; ++a) {
  save();
  point P = (-4.5, 0); dot(P);
  inversion inv = inversion(1, P);
  line l1 = line((0, 0), (-0.35, 1)), l2 = line((0, 0), (0.35, 1));
  path g1 = inv*l1, g2=inv*l2;

  fill(g1^^g2, evenodd+lightgrey); draw(g1, linewidth(bp));
  draw(g2, linewidth(bp));

  for (int i:new int[]{-1, 1}) {
    point P = (0, 3i/a);
    triangle t = triangle(shift(P)*hline, l1, l2);
    int n = a;

    for (int j = 0; j <= n; ++j) {
      circle C = excircle(t.AB);
      t = triangle(shift(angpoint(C, i*90))*hline, l1, l2);
      circle Cp = inv*C;
      path g = Cp;

      fill(g, 0.95*yellow);
      draw(g, bp+red); draw(g, blue);
    }
  }

  picture pic;
  add(pic, bbox(5mm, Fill(rgb(0.95, 0.95, 0.8))));
  A.add(pic);
  restore();
}

A.pdf(keep = true);

🔗animations-fig003

Show animations/fig0030.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Animation | #Geometry | #Shading

import geometry;
import animate;
animation A;

size(15cm);

int nAnim = 75;
int nCircle = 6;
real astep = 360/nAnim;

inversion inv = inversion((-1, -2), 1);
line L1 = line(N, S);
circle C = inv * L1;
point center = C.C;

for (int i = -nAnim; i < nAnim; ++i) {
  real r;
  r = 0.001 + 4 * (i/nAnim)^2;
  line L2 = shift(2 * r * E) * L1;
  transform T = shift(0, -2 * r);
  transform R = rotate(astep * i, center);
  point C0c = r * E + nCircle/2 * sqrt(r) * N;
  circle[] Ci = sequence(new circle(int i){return circle(T^i * C0c, r);},  nCircle);

  fill(R * (path)C,  0.3 * blue);
  circle Cl = (circle) (R * (inv * L2));
  transform dsh = shift(Cl.r / 3 * unit(center-Cl.C));
  radialshade((path)Cl, white, dsh * Cl.C, 0, black, dsh * Cl.C, Cl.r);

  for (int i = 0; i < Ci.length; ++i) {
    circle Ct = inv * Ci[i];
    transform dsh = shift(Ct.r/3 * unit(center-Ct.C));
    radialshade(R * (path)Ct, red, dsh * R * Ct.C, 0, black, dsh * R * Ct.C, Ct.r);
  }

  A.add();
  erase();
}

A.movie(BBox(2mm, Fill(black)));

🔗animations-fig004

Show animations/fig0040.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Geometry | #Animation | #Triangle | #Circle | #Locus

import geometry;
import animate;
animation Anim;

size(12cm);

circle C=circle(origin, 1);
draw(C);
point A=point(C, 0), B, M;
guide locus;

for (real a=0.001; a < 360; a += 5) {
  save();
  B=angpoint(C,a);
  triangle t=triangle(origin, A, B);
  draw(t);
  draw(incircle(t), bp+0.8*blue);
  triangle intouch=intouch(t);
  draw(intouch, dot);
  M=intouch(t.AC);
  label("$N$", Label("$M$", 0.8*red), "$P$", intouch);
  dot(M, 0.8*red);
  locus=locus..M;
  draw(locus, bp+0.8*red);
  Anim.add();
  restore();
}

Anim.movie();

🔗animations-fig005

Author : Jens Schwaiger.

Show animations/fig0060.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Animation | #Polyhedron | #Solid

import polyhedron_js;
import animate;
settings.render=0;
settings.tex="pdflatex";
settings.outformat="pdf";

size(16cm);
currentprojection=perspective(5,4,2);
currentlight=(5,4,2);

polyhedron Plane;
Plane[0]=(-2,-2,-1.5)--(2.5,-2,-1.5)--(2.5,2.5,-1.5)--(-2,2.5,-1.5)--cycle;
Plane[1]=(-2,-2,-1.5)--(-2,2.5,-1.5)--(-2,2.5,0)--(-2,-2,0)--cycle;

int n=180;
pen[] drawcol={black+1bp};
pen[] fcol1={0.8*red,0.8*blue,0.8*green,orange,heavycyan,gray};

animation anim;

triple[] posofsolids;
real angle;
for(int janim=0; janim < n; ++janim){
  for(int i=0; i < 5; ++i) {
    angle=2pi/5*i+2pi*janim/n;
    posofsolids[i]=(1.7*cos(angle)+1,1.7*sin(angle)+1,0);
  }
  transform3 T=rotate(-degrees(2*angle),Z);
  polyhedron[] parr={ shift(posofsolids[0])*T*icosahedron,
                      shift(posofsolids[1])*T*dodecahedron,
                      shift(posofsolids[2])*T*cube,
                      shift(posofsolids[3])*T*rotate(45,Z)*octahedron,
                      shift(posofsolids[4])*T*rotate(90,Z)*tetrahedron,
                      Plane };

  save();
  filldraw(parr,fcol=fcol1,dcol=drawcol,op=0.9);
  anim.add();
  restore();
}

anim.movie(BBox(3mm,darkblue+3bp+miterjoin,FillDraw(paleblue)));

🔗animations-fig006

Show animations/fig0070.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Animation | #Polyhedron | #Solid

import polyhedron_js;
import animation;

settings.tex="pdflatex";
settings.outformat="pdf"; // for opacity
settings.render=0;

animation A;
size(8cm);

// currentprojection=perspective(7,6,4); //if you want perspectivic look
currentprojection=orthographic(1,0.5,1); //if you want othographic look
currentlight=(1,1,2);
// currentlight=nolight;

int col=0;
pen[] fcol={palegreen+paleblue+lightgrey};
fcol.cyclic=true;

polyhedron[] parr;

for (int i=0; i < 360; i += 2) {
  parr[0]=rotate(i,Z)*rhombicosDodec;
  save();
  filldraw(parr,fcol,op=0.9);
  A.add();
  restore();
}

A.movie();

🔗animations-fig007

Show animations/fig0080.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Graph (3D) | #Function (graphing) | #Animation | #Sphere | #Surface | #Path3 | #Segment

size(16cm);
import graph3;
import animation;
import solids;

settings.render=0;
animation A;

int nbpts=500;
real q=2/5;
real pas=5*2*pi/nbpts;
int angle=3;
real R=3;

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

🔗animations-fig008

Show animations/fig0090.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Graph (3D) | #Function (graphing) | #Animation | #Sphere | #Surface | #Path3 | #Segment | #Projection (3D) | #Plane

size(16cm);
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();

🔗animations-fig009

Show animations/fig0100.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Physics | #Graph | #Typedef | #Function (graphing) | #Animation

import animation;
import graph;

settings.tex="pdflatex";
settings.outformat="pdf";

unitsize(x=2cm,y=1.5cm);

typedef real realfcn(real);

real lambda=4;
real T=2;
real [] k=new real[3];
real [] w=new real[3];
k[0]=2pi/lambda;
w[0]=2pi/T;
real dk=-.5;
k[1]=k[0]-dk;
k[2]=k[0]+dk;
real dw=1;
w[1]=w[0]-dw;
w[2]=w[0]+dw;

real vp=w[1]/k[1];
real vg=dw/dk;

realfcn F(real x) {
  return new real(real t) {
    return cos(k[1]*x-w[1]*t)+cos(k[2]*x-w[2]*t);
  };
};

realfcn G(real x) {
  return new real(real t) {
    return 2*cos(0.5*(k[2]-k[1])*x+0.5*(w[1]-w[2])*t);
  };
};

realfcn operator -(realfcn f) {return new real(real t) {return -f(t);};};

animation A;

real tmax=abs(2pi/dk);
real xmax=abs(2pi/dw);

pen envelope=0.8*blue;
pen fillpen=lightgrey;

int n=50;
real step=tmax/(n-1);
for(int i=0; i < n; ++i) {
  save();
  real t=i*step;
  real a=xmax*t/tmax-xmax/pi;
  real b=xmax*t/tmax;
  path f=graph(F(t),a,b);
  path g=graph(G(t),a,b);
  path h=graph(-G(t),a,b);
  fill(buildcycle(reverse(f),g),fillpen);
  draw(f);
  draw(g,envelope);
  draw(h,envelope);
  A.add();
  restore();
}

for(int i=0; i < n; ++i) {
  save();
  real t=i*step;
  real a=-xmax/pi;
  real b=xmax;
  path f=graph(F(t),a,b);
  path g=graph(G(t),a,b);
  path h=graph(-G(t),a,b);
  path B=box((-xmax/pi,-2),(xmax,2));
  fill(buildcycle(reverse(f),g,B),fillpen);
  fill(buildcycle(f,g,reverse(B)),fillpen);
  draw(f);
  draw(g,envelope);
  draw(h,envelope);
  A.add();
  restore();
}

A.movie();

🔗animations-fig010

Show animations/fig0110.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Ellipse | #Tangent | #Geometry | #Animation

import geometry;
import animate;
// settings.tex="pdflatex";
// settings.outformat="pdf";

animation anim;
size(12cm);

point F1=(0, 0), F2=(0, -3);
dot("F", F1);

ellipse el1=ellipse(F1, F2, 2), el2;
point Fp1=shift(0, 2*el1.a)*F1;
dot("F'", Fp1);

line tgt, saxe=line(F1, false, -F2);

for (int i=0; i < 360; i += 5) {
  save();
  ellipse el=rotate(i, F1)*el1;
  point M=intersectionpoints(el, saxe)[0];
  tgt=tangents(el, M)[0];
  draw(tgt, 0.8*red);
  draw((reflect(tgt)*el)^^el, linewidth(bp));
  anim.add();
  restore();
}

erase();
anim.movie();

🔗animations-fig011

Show animations/fig0120.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Ellipse | #Tangent | #Geometry | #Animation | #Locus

import geometry;
import animate;

animation anim;
size(16cm);

point F1=(0, 0), F2=(10, 0);
dot("F", F2);
ellipse el1=ellipse(F1, F2, 6), el2;
draw(el1, linewidth(bp));
point Fp2=shift(2*el1.a, 0)*F2;
line tgt, saxe;
pen[] p=new pen[]{0.8*green, 0.8*blue, 0.8*yellow, cyan};
path[] locus=sequence(new path(int i){return nullpath;}, p.length);
real t=1/(p.length-1);

bool initlocus=true;
for (int i=0; i < 360; i += 1) {
  save();
  point Fm=rotate(i, F2)*Fp2;
  dot("F'", Fm);
  draw(Fm--F2, linewidth(2bp));
  point M=intersectionpoints(el1, line(F2, false, Fm))[0];
  tgt=tangents(el1, M)[0];
  draw(tgt, 0.8*red);
  el2=reflect(tgt)*el1;
  draw(el2.F1--el2.F2);

  for (int j=0; j < p.length; ++j) {
    point P=point(segment(el2.F2, Fm), 0.5+j*t/2);
    locus[j]=initlocus ? P : locus[j]--P;
    dot(P, p[j]);
    draw(locus[j], bp+p[j]);
  }

  dot(el2.F2);
  draw(el2, linewidth(bp));
  anim.add();
  restore();
  initlocus=false;
}

erase();
anim.movie();

🔗animations-fig012

Show animations/fig0130.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Animation | #Geometry | #Graph

import geometry;
import animate;

point A=(0, 0), B=(8, 0), C=(8, 10);
unitsize(5cm/B.x, 5cm/C.y);
animation Anim, Anim1;
path locus;

triangle t=triangle(A, B, C);
transform proj=projection(t.BC);
draw(t, linewidth(bp));
label(t);
segment s=segment(t.AB);
line l1 =line(t.BC);

int n=50; // Points number of the locus
real a=0, step=1/(n-1);
for (int i=0; i < n; ++i) {
  save(); // Geometry part
  point M=point(s, a);
  line l2=parallel(M, l1);
  point Np=intersectionpoint(l2, t.AC);
  point P=proj*Np;
  dot("$M$", M, S, 0.8*red);
  dot("$P$", P, E, 0.8*red);
  dot("$N$", Np, W, 0.8*red);
  fill(M--Np--P--B--cycle, 0.8*red);
  perpendicularmark(t.BC, t.BA);
  Anim.add(); // Anim contain only the geometry part
  restore();
  // Graph part
  picture gph; // picture of the graph
  unitsize(gph, 5cm/B.x, 4cm/C.y); // units for the graph
  show(gph, currentcoordsys);
  point Sp=(a*abs(B-A), abs(M-B)*abs(M-Np));
  locus=locus..Sp;
  draw(gph, locus, bp+0.8*red);
  Anim1.add(gph); // Anim1 contain only the graph part
  a += step;
}

Anim1.export(); // make all Anim1 pictures to the same size.
Anim1.purge();

for (int i=0; i < Anim.pictures.length; ++i) {
  // draw axis on all pictures of Anim1
  draw(Anim1.pictures[i], Label("$x$", align=S, position=EndPoint), hline, Arrow);
  draw(Anim1.pictures[i], Label("$y$", align=W, position=EndPoint), vline, Arrow);
  // add each graph to the corresponding geometric picture
  add(Anim.pictures[i], Anim1.pictures[i].fit(), 1.25*B);
}

Anim.movie();

🔗animations-fig013

Inspiration.

Show animations/fig0140.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #L-System | #Animation

import Lsystem;
import animate;
animation A = animation(global=false);

size(16cm, 12cm);

string[][] rules={{"A", "[+BFA][-BFA][^BFA][&BFA]"}, {"B", "'(0.7071)"}};
Lsystem3 plant=Lsystem3("A", rules, La=45);
plant.iterate(5);
tree3 g=plant.tree3();

for (int angle=0; angle < 360; angle += 5) {
  currentprojection=orthographic(rotate(angle, Z)*(10, 10, 6));
  save();
  for (int i : g.keys)
    draw((path3)g[i], linewidth(bp)+(g[i].depth > 3 ? brown : 0.8*green));
  A.add();
  restore();
}

A.movie(BBox(3mm, Fill(yellow+blue)));

🔗animations-fig014

Show animations/fig0150.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Animation | #L-System | #Path3

import Lsystem;
import animate;

settings.tex="pdflatex";
settings.outformat="pdf";

animation A;
size(10cm,0);

string[][] rules={{"X","^<XF^<XFX-F^>>XFX&F+>>XFX-F>X->"}};
Lsystem3 HilbertCurve3D=Lsystem3("X", rules, La=90, Lai=0);
HilbertCurve3D.iterate(3);

path3[] g=HilbertCurve3D.paths3();
triple M=(max(g)+min(g))/2;
currentprojection=currentprojection=orthographic((10,10,6));

for (int angle=0; angle < 360; angle += 2) {
  save();
  draw(rotate(angle,M,M+Z)*g[0], linewidth(bp)+0.9*yellow);
  A.add();
  restore();
}

A.movie(BBox(3mm, Fill(black)));

🔗animations-fig015

Show animations/fig0160.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Morphing | #Fill/Unfill | #Pen | #Animation

import graph_settings;
import animate;
size(16cm);

pair[] interp(pair[] a1, pair[] a2, real k)
{
  if(a1.length != a2.length) abort("interp: arrays have differents length.");
  pair[] g;
  int l=a1.length;
  g=sequence(new pair(int j){
      return interp(a1[j], a2[j], k);
    }, l);
  return g;
}

path morphing(pair[] a1, pair[] a2, real k, interpolate join=operator --)
{
  if(a1.length != a2.length) abort("morphing: arrays have differents length.");
  return join(...interp(a1, a2, k));
}

pair[] nodes(path g, int n)
{
  int np=round(n/length(g));
  n=np == 0 ? n : np*length(g);
  return sequence(new pair(int i){return point(g, length(g)*i/n);}, n);
}

animation A;

int nbpt=4;
pair[] A1=nodes(unitsquare, nbpt);
path g=(0, 0)--(1, 0)--(0, 1)--(1, 1)--cycle;
pair[] A2=shift(2, 1)*rotate(25)*nodes(g, nbpt);
interpolate join=operator ..;
// interpolate join=operator --;


int n=40;
real step=1/n;
pen p1=0.8*red, p2=0.8*blue;

filldraw(join(morphing(A1, A2, 0, join), cycle), p1);
filldraw(join(morphing(A1, A2, 1, join), cycle), p2);

for (int i=0; i <= n; ++i) {
  save();
  filldraw(join(morphing(A1, A2, i*step, join), cycle), opacity(0.5)+interp(p1, p2, i*step));
  A.add();
  restore();
}

A.movie(BBox(3mm, Fill(white)));

🔗animations-fig016

Show animations/fig0170.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Morphing | #Fill/Unfill | #Pen | #Animation

import graph;
import animate;
size(15cm);

pair[] interp(pair[] a1, pair[] a2, real k)
{
  if(a1.length != a2.length) abort("interp: arrays have differents length.");
  pair[] g;
  int l=a1.length;
  g=sequence(new pair(int j){
      return interp(a1[j],a2[j],k);
    },l);
  return g;
}

path morphing(pair[] a1, pair[] a2, real k, interpolate join=operator --)
{
  if(a1.length != a2.length) abort("morphing: arrays have differents length.");
  return join(...interp(a1, a2, k));
}

pair[] nodes(path g, int n)
{
  int np=round(n/length(g));
  n=np == 0 ? n : np*length(g);
  return sequence(new pair(int i){return point(g, length(g)*i/n);}, n);
}

animation A;

real f(real t){ return exp(cos(t))-2*cos(4*t)+sin(t/12)^5;}
path gf=polargraph(f,0,12*pi,1000);

int nbpt=1000;
pair[] A1=nodes(scale(5.5)*unitcircle,nbpt);
pair[] A2=shift(0,0)*nodes(gf,nbpt);
interpolate join=operator --;


int n=50;
real step=1/n;
pen p1=0.8*red, p2=0.8*blue;

for (int i=0; i <= n; ++i) {
  save();
  filldraw(join(morphing(A1,A2,1,join),cycle),
           evenodd+p2);
  filldraw(join(morphing(A1,A2,i*step,join),cycle),
           evenodd+interp(p1,p2,i*step));
  A.add();
  restore();
}

int l = A.pictures.length;
for (int i=1; i <= l; ++i) {
  A.add(A.pictures[l-i]);
}

A.movie(BBox(3mm, 3bp+miterjoin+black, FillDraw(lightyellow)));

🔗animations-fig017

Show animations/fig0180.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Animation | #Label | #Geometry

import labelpath;
import animate;
animation A;

size(16cm, 0);

usepackage("mathrsfs, amsfonts, amsmath, amssymb");
picture pic, pic1, pic2, pic3;
real u = 1, Y = 2 * pi+0.5;
pair yM = (u, Y * u), ym = (u, -Y * u);
path cle = scale(u) * unitcircle;
path arcg = arc((0, 0), 1.5 * u, 115, 155);

void addtick(picture pic = currentpicture, Label L, pair z, pair dir = E, pen p = currentpen)
{
  transform R = rotate(degrees(dir));
  real width = 1.5mm;
  Label L = L.copy();
  L.position(z);
  L.align(NoAlign, E);
  L.align.dir = R * L.align.dir * 1.3 * width/mm;
  L.p(p);

  pic.add(new void(frame f, transform t) {
      path g = (-width, 0)--(width, 0);
      picture opic;

      draw(opic, shift(t * z) * R * g, p);
      add(f, opic.fit());
    });

  add(pic, L);
}

pair EW(int sign){return sign > 0 ? E : W;}

string pm(int sign){return sign > 0 ? "" : "-";}

pen p(int sign){return sign > 0 ? red : blue;}
pen pw(int sign){return p(sign)+(sign > 0 ? currentpen : white);}

// Define common picture
draw(scale(1.25) * "+", arcg, Arrow());
dot("$0$", point(cle, 0));

draw((-u, 0)--(u, 0)^^(0, -u)--(0, u));
draw("$1$", (0, 0)--point(cle, 1.5), Arrows(FillDraw(white)));

pic.add(currentpicture);// Save the common picture in 'pic'.

// Starting picture 1
draw((u, 0)--yM, linewidth(bp)+p(1), Arrow(TeXHead));
draw(ym--(u, 0), linewidth(bp)+p(-1));
arrow("\underline{Axe des reels}", (u, -0.75 * Y * u), W, 1cm);

real x = 2.2, y = -x, maxe = 2 * pi+0.2;
addtick(Label("$1$", align = E), (u, 1), p(1));
addtick(Label("$\frac{\pi}{2}$", align = E), (u, pi/2), p(1));
addtick(Label("$\pi$", align = E), (u, pi), p(1));
addtick(Label("$\frac{3\pi}{2}$", align = E), (u, 3pi/2), p(1));
addtick(Label("$2\pi$", align = E), (u, 2pi), p(1));
addtick(Label("$-1$", align = W), (u, -1), p(-1));
addtick(Label("$-\frac{\pi}{2}$", align = W), (u, -pi/2), p(-1));
addtick(Label("$-\pi$", align = W), (u, -pi), p(-1));
addtick(Label("$-\frac{3\pi}{2}$", align = W), (u, -3pi/2), p(-1));
addtick(Label("$-2\pi$", align = W), (u, -2pi), p(-1));

draw(Label("$\mathscr{C}$", Relative(0.625)), cle, linewidth(bp));
A.add();
erase();

// Define the common picture for rolling part.
picture picanim(int sign)
{
  picture opic = pic.copy();
  pen pmoins = sign > 0 ? p(-1) : p(-1)+white;
  draw(opic, (u, 0)--yM, bp+white+p(1), Arrow(TeXHead));
  draw(opic, ym--(u, 0), linewidth(bp)+pmoins);
  arrow(opic, "\underline{Axe des reels}", (u, -0.75 * Y * u), W, 1cm);
  addtick(opic, Label("$1$", align = E), (u, 1), white+p(1));
  addtick(opic, Label("$\frac{\pi}{2}$", align = E), (u, pi/2), white+p(1));
  addtick(opic, Label("$\pi$", align = E), (u, pi), white+p(1));
  addtick(opic, Label("$\frac{3\pi}{2}$", align = E), (u, 3pi/2), white+p(1));
  addtick(opic, Label("$2\pi$", align = E), (u, 2 * pi), white+p(1));
  addtick(opic, Label("$-1$", align = W), (u, -1), pmoins);
  addtick(opic, Label("$-\frac{\pi}{2}$", align = W), (u, -pi/2), pmoins);
  addtick(opic, Label("$-\pi$", align = W), (u, -pi), pmoins);
  addtick(opic, Label("$-\frac{3\pi}{2}$", align = W), (u, -3pi/2), pmoins);
  addtick(opic, Label("$-2\pi$", align = W), (u, -2 * pi), pmoins);
  return opic;
}

erase();
pic2 = picanim(1);

int nb = 50; // Number of picture for rolling.
real step = maxe/nb;

for (int sign = 1; sign > -2; sign -= 2) {// Rolling axis part (1 for positive values, -1 for ...);
  guide r1, rpis2, rpi, rpi32, rpi2;
  pair z;

  for (int i = 0; i <= nb ; ++i) {
    real t = sign * i * step; // Where is the tangency.

    if(sign > 0) draw(Label("$\mathscr{C}$", Relative(0.625)), cle, linewidth(bp));
    path tg = i == nb ? cle : arc((0, 0), u, 0, degrees(t)); // The rolled part.
    path g = u * expi(t)--shift(u * expi(t)) * ((Y-abs(t)) * u * expi(sign * pi/2+t)); // The straight part.
    draw(g, linewidth(bp)+p(sign), sign > 0 ? Arrow(TeXHead) : None);

    if(t > 0) {
      if(abs(t) <= 1) {
        z = arcpoint(g, (1-abs(t)) * u);
        addtick(Label(pm(sign) + "$1$", align = EW(sign)), z, expi(sign), p(sign));
        r1 = r1..z;
      } else addtick(Label(pm(sign) + "$1$", align = EW(sign), UnFill),
                     u * (cos(sign), sin(sign)), dir(degrees(sign * 1.0)), p(sign));}

    draw(r1, dashed+p(sign));

    if(abs(t) <= pi/2) {
      z = arcpoint(g, (pi / 2 - abs(t)) * u);
      addtick(Label("$"+pm(sign)+"\frac{\pi}{2}$", align = EW(sign)), z, expi(t), p(sign));
      rpis2 = rpis2..z;
    } else addtick(Label("$"+pm(sign)+"\frac{\pi}{2}$", align = EW(sign), UnFill),
                   (0, sign*u), sign*N, p(sign));

    draw(rpis2, dashed+p(sign));

    if(abs(t) <= pi) {
      z = arcpoint(g, (pi-abs(t))*u);
      addtick(Label("$"+pm(sign)+"\pi$", align = EW(sign)), z, expi(t), p(sign));
      rpi = rpi..z;
    } else addtick(Label("$"+pm(sign)+"\pi$", align = EW(sign), UnFill),
                   (-u, 0), W, p(sign));

    draw(rpi, dashed);

    if(abs(t) <= 3*pi/2) {
      z = arcpoint(g, (3pi/2-abs(t))*u);
      addtick(Label("$"+pm(sign)+"\frac{3\pi}{2}$", align = EW(sign)), z, expi(t), p(sign));
      rpi32 = rpi32..z;
    } else addtick(Label("$"+pm(sign)+"\frac{3\pi}{2}$", align = EW(sign), UnFill),
                   (0, -sign*u), sign*S, p(sign));

    draw(rpi32, dashed+p(sign));

    if(abs(t)-2*pi < -1e-5) {
      z = arcpoint(g, (2*pi-abs(t))*u);
      addtick(Label("$"+pm(sign)+"2\pi$", align = EW(sign)), z, expi(t), p(sign));
      rpi2 = rpi2..z;
    } else addtick(Label("$"+pm(sign)+"2\pi$", align = (sign > 0 ? 2 : 1)*EW(sign), UnFill),
                   (u, 0), E, p(sign));

    draw(rpi2, dashed+p(sign));

    if(i == nb && sign == 1) {
      draw(tg, linewidth(2*bp)+p(sign));
      pic3.add(currentpicture);
      add(pic2);
      pic2 = picanim(-1);
      pic2.add(pic3);
    } else add(pic2); // Add the common picture 'pic2'.

    draw(tg, linewidth(bp) + p(sign));

    A.add();
    if(sign > 0 || i != nb) erase();
  }
}

for (int i = 0; i < 20; ++i) A.add();

// eval(quote{
//     addtick(Label("$-\pi$", align = EW(-1), UnFill), (-u, 0), W, p(-1));
//     addtick(Label("$-2\pi$", align = EW(-1), UnFill), (u, 0), E, p(-1));
//     defaultfilename = 'temp_';
//     shipout(currentpicture.fit(scale(2cm)));}, true);

// pair center = (min(currentpicture) + max(currentpicture)) / 2;
// int n = 20;
// for (int i = 0; i <= n; ++i) {
//   erase();
//   label(scale(1 + 1.25 * i / n) * graphic("temp_.pdf"), i / n * center);
//   A.add();
// }

// for (int i = 0; i < 20; ++i) A.add();
// for (int i = 0; i < 10; ++i) A.add(A.pictures[0]); // Add the first picture in the animation.

erase();

A.movie();

🔗animations-fig018

Show animations/fig0190.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Animation
Tags : #Numerical Methods | #Animation

size(12cm,0);
import hull_pi;
import animation;
animation A;
settings.outformat="pdf";
A.global = false;

pair[] cloud;
int nbpt=200;

// Generate random points.
for (int i=0; i < nbpt; ++i)
  cloud.push((10*unitrand(),10*unitrand()));

for (int i=1; i < 8; ++i) { // Control the depth
  for (int j=0; j < 30; ++j) { // Point of view = cloud[i]
    real depthMax=i/2;
    // Nodes of the hull
    pair[] hull=hull(cloud,depthMin=0,depthMax=depthMax,angleMin=10,angleMax=360,pivot=j);

    save();// Add new picture to the animation
    filldraw(polygon(hull),lightgrey);
    dot(cloud[j],3mm+green);
    dot(cloud,red);
    label("depthMax="+(string)depthMax);
    A.add();
    restore();
  }
}

A.movie();

0%