Random walk in the space – fig0010

Category: Asymptote,Examples 3D,Random Walk (3D)Ph. Ivaldi @ 11 h 46 min

Figure 0001
(Compiled with Asymptote version 1.84svn-r4619)
    
import three;
settings.render=0;

// The available directions of steps
triple[] dirs={X,-X,Y,-Y,Z,-Z};
dirs.cyclic=true;

// Return the nodes of the path
triple[] randWalk(real Srnd(), int n)
{
  triple[] randPath;
  triple camera=1e10*currentprojection.camera;
  triple pos=O, tpos;
  int R;
  for (int i=0; i < n; ++i) {
    R=round(Srnd());
    tpos=pos+dirs[R];
    randPath.push(tpos);
    pos=tpos;
  }
  return randPath;
}
triple[] randWalk(int Srnd(), int n)
{
  real R(){ return Srnd();}
  return randWalk(R,n);
}

void drawWalk(triple[] nodes, pen p=white)
{
  triple camera=currentprojection.camera;
  if(currentprojection.infinity)
    camera *= max(abs(minbound(nodes)),abs(maxbound(nodes)));
  real[][] depth;
  for(int i=0; i < nodes.length-1; ++i) {
    real d=abs(camera-0.5*(nodes[i]+nodes[i+1]));
    depth.push(new real[] {d,i});
  }
  depth=sort(depth);
  triple M=nodes[round(depth[0][1])];
  triple m=nodes[round(depth[depth.length-1][1]+1)];
  // Draw from farthest to nearest
  while(depth.length > 0) {
    real[] a=depth.pop();
    int i=round(a[1]);
    draw(nodes[i]--nodes[i+1],abs(nodes[i]-m)/abs(M-m)*p);
  }
}


size(18cm);
currentprojection=orthographic((1,1,1));

drawWalk(randWalk(rand,50000),cyan);
shipout(bbox(3mm,Fill));

Mots-clés : , , ,


Random walk in the space – fig0020

Category: Asymptote,Examples 3D,Random Walk (3D)Ph. Ivaldi @ 12 h 46 min

Figure 0002
(Compiled with Asymptote version 1.84svn-r4619)
    
import three;
settings.render=0;

// The available directions of steps
triple[] dirs={X,-X,Y,-Y,Z,-Z};
dirs.cyclic=true;

struct walk
{
  triple[] nodes;
  pen[] p;
}

// Comput the nodes of the path
walk randWalk(real Srnd(), int n, pen[] p={currentpen})
{
  p.cyclic=true;
  walk ow;
  triple pos=O, tpos;
  for (int i=0; i < n; ++i) {
    int R=round(Srnd());
    tpos=pos+dirs[R];
    ow.nodes.push(tpos);
    ow.p.push(p[R]);
    pos=tpos;
  }
  return ow;
}

walk randWalk(int Srnd(), int n, pen[] p={currentpen})
{
  real R(){ return Srnd();}
  return randWalk(R,n,p);
}

void drawWalk(walk walk)
{
  triple camera=currentprojection.camera;
  if(currentprojection.infinity)
    camera *= max(abs(minbound(walk.nodes)),abs(maxbound(walk.nodes)));
  real[][] depth;
  for(int i=0; i < walk.nodes.length-1; ++i) {
    real d=abs(camera-0.5*(walk.nodes[i]+walk.nodes[i+1]));
    depth.push(new real[] {d,i});
  }
  depth=sort(depth);
  triple M=walk.nodes[round(depth[0][1])];
  triple m=walk.nodes[round(depth[depth.length-1][1]+1)];
  // Draw from farthest to nearest
  while(depth.length > 0) {
    real[] a=depth.pop();
    int i=round(a[1]);
    // dot(walk.nodes[i],walk.p[i]);
    draw(walk.nodes[i]--walk.nodes[i+1],abs(walk.nodes[i]-m)/abs(M-m)*(walk.p[i]+walk.p[i+1]));
  }
}


size(18cm);
currentprojection=orthographic((0.5,0.5,1));

drawWalk(randWalk(rand,50000,new pen[]{red, blue, green, yellow, purple}));
shipout(bbox(3mm,Fill));

Mots-clés : ,


Random walk in the space – fig0030

Category: Asymptote,Examples 3D,Random Walk (3D)Ph. Ivaldi @ 13 h 46 min

Figure 0003
(Compiled with Asymptote version 1.84svn-r4619)
    
import three;
import stats;
settings.render=0;

string[] dirs={"U","D","B","F","R","L"};
// U=up, D=down, B=backward, F=forward, R=right, L=left
dirs.cyclic=true;

// Comput the nodes of the path
triple[] randWalk(real Srnd(), int n, real angle=90)
{
  triple[] randPath;
  triple udir=Z, vdir=X, kdir=cross(udir,vdir);
  triple pos=O, tpos;
  void changedir(real angle, triple axe)
  {
    transform3 T=rotate(angle,axe);
    udir=T*udir;
    vdir=T*vdir;
    kdir=T*kdir;
  }
  void nextdir()
  {
    string R=dirs[round(Srnd())];
    if(R == "R") changedir(-angle,kdir);
    else if(R == "L") changedir(angle,kdir);
    else if(R == "U") changedir(angle,vdir);
    else if(R == "D") changedir(-angle,vdir);
    else if(R == "B") changedir(180,udir);
  }
  for (int i=0; i < n; ++i) {
    tpos=pos+udir;
    randPath.push(tpos);
    pos=tpos;
    nextdir();
  }
  return randPath;
}

triple[] randWalk(int Srnd(), int n, real angle=90)
{
  real R(){ return Srnd();}
  return randWalk(R,n,angle);
}

void drawWalk(triple[] nodes, pen p=white)
{
  triple camera=currentprojection.camera;
  if(currentprojection.infinity)
    camera *= max(abs(minbound(nodes)),abs(maxbound(nodes)));
  real[][] depth;
  for(int i=0; i < nodes.length-1; ++i) {
    real d=abs(camera-0.5*(nodes[i]+nodes[i+1]));
    depth.push(new real[] {d,i});
  }
  depth=sort(depth);
  triple M=nodes[round(depth[0][1])];
  triple m=nodes[round(depth[depth.length-1][1]+1)];
  // Draw from farthest to nearest
  while(depth.length > 0) {
    real[] a=depth.pop();
    int i=round(a[1]);
    draw(nodes[i]--nodes[i+1],abs(nodes[i]-M)/abs(M-m)*p);
  }
}


size(18cm);
currentprojection=orthographic((0.5,0.5,1));

drawWalk(randWalk(Gaussrand,50000));

Mots-clés :


Random walk in the space – fig0040

Category: Asymptote,Examples 3D,Random Walk (3D)Ph. Ivaldi @ 14 h 46 min

Figure 0004
(Compiled with Asymptote version 1.84svn-r4619)
    
import three;
import stats;
settings.render=0;

struct walk
{
  triple[] nodes;
  pen[] p;
}

string[] dirs={"U","D","B","F","R","L"};
// U=up, D=down, B=backward, F=forward, R=right, L=left
dirs.cyclic=true;

// Comput the nodes of the path
walk randWalk(real Srnd(), int n, real angle=90, pen[] p={currentpen})
{
  p.cyclic=true;
  walk ow;
  triple udir=Z, vdir=X, kdir=cross(udir,vdir);
  triple pos=O, tpos;
  void changedir(real angle, triple axe)
  {
    transform3 T=rotate(angle,axe);
    udir=T*udir;
    vdir=T*vdir;
    kdir=T*kdir;
  }
  void nextdir()
  {
    int rd=round(Srnd());
    ow.p.push(p[rd]);
    string R=dirs[rd];
    if(R == "R") changedir(-angle,kdir);
    else if(R == "L") changedir(angle,kdir);
    else if(R == "U") changedir(angle,vdir);
    else if(R == "D") changedir(-angle,vdir);
    else if(R == "B") changedir(180,udir);
  }
  for (int i=0; i < n; ++i) {
    tpos=pos+udir;
    ow.nodes.push(tpos);
    pos=tpos;
    nextdir();
  }
  return ow;
}

walk randWalk(int Srnd(), int n, real angle=90, pen[] p={currentpen})
{
  real R(){ return Srnd();}
  return randWalk(R,n,angle,p);
}

void drawWalk(walk walk)
{
  triple camera=currentprojection.camera;
  if(currentprojection.infinity)
    camera *= max(abs(minbound(walk.nodes)),abs(maxbound(walk.nodes)));
  real[][] depth;
  for(int i=0; i < walk.nodes.length-1; ++i) {
    real d=abs(camera-0.5*(walk.nodes[i]+walk.nodes[i+1]));
    depth.push(new real[] {d,i});
  }
  depth=sort(depth);
  triple M=walk.nodes[round(depth[0][1])];
  triple m=walk.nodes[round(depth[depth.length-1][1]+1)];
  // Draw from farthest to nearest
  while(depth.length > 0) {
    real[] a=depth.pop();
    int i=round(a[1]);
    draw(walk.nodes[i]--walk.nodes[i+1],
         abs(walk.nodes[i]-m)/abs(M-m)*walk.p[i]);
  }
}


size(18cm);
currentprojection=orthographic((0.5,0.5,1));

drawWalk(randWalk(Gaussrand,50000,new pen[] {red,yellow,blue}));
shipout(bbox(3mm,Fill));

Mots-clés :


Random walk in the space – fig0050

Category: Asymptote,Examples 3D,Random Walk (3D)Ph. Ivaldi @ 15 h 46 min

Figure 0005
(Compiled with Asymptote version 1.84svn-r4619)
    
import three;
import stats;
settings.render=0;

struct walk
{
  triple[] nodes;
  pen[] p;
}

string[] dirs={"U","D","B","F","R","L"};
// U=up, D=down, B=backward, F=forward, R=right, L=left
dirs.cyclic=true;

// Comput the nodes of the path
walk randWalk(real Srnd(), int n, real angle=90, pen[] p={currentpen})
{
  p.cyclic=true;
  walk ow;
  triple udir=Z, vdir=X, kdir=cross(udir,vdir);
  triple pos=O, tpos;
  void changedir(real angle, triple axe)
  {
    transform3 T=rotate(angle,axe);
    udir=T*udir;
    vdir=T*vdir;
    kdir=T*kdir;
  }
  void nextdir()
  {
    int rd=round(Srnd());
    ow.p.push(p[rd]);
    string R=dirs[rd];
    if(R == "R") changedir(-angle,kdir);
    else if(R == "L") changedir(angle,kdir);
    else if(R == "U") changedir(angle,vdir);
    else if(R == "D") changedir(-angle,vdir);
    else if(R == "B") changedir(180,udir);
  }
  for (int i=0; i < n; ++i) {
    tpos=pos+udir;
    ow.nodes.push(tpos);
    pos=tpos;
    nextdir();
  }
  return ow;
}

walk randWalk(int Srnd(), int n, real angle=90, pen[] p={currentpen})
{
  real R(){ return Srnd();}
  return randWalk(R,n,angle,p);
}

void drawWalk(walk walk)
{
  triple camera=currentprojection.camera;
  if(currentprojection.infinity)
    camera *= max(abs(minbound(walk.nodes)),abs(maxbound(walk.nodes)));
  real[][] depth;
  for(int i=0; i < walk.nodes.length-1; ++i) {
    real d=abs(camera-0.5*(walk.nodes[i]+walk.nodes[i+1]));
    depth.push(new real[] {d,i});
  }
  depth=sort(depth);
  triple M=walk.nodes[round(depth[0][1])];
  triple m=walk.nodes[round(depth[depth.length-1][1]+1)];
  // Draw from farthest to nearest
  while(depth.length > 0) {
    real[] a=depth.pop();
    int i=round(a[1]);
    draw(walk.nodes[i]--walk.nodes[i+1],
         abs(walk.nodes[i]-m)/abs(M-m)*walk.p[i]);
  }
}


size(18cm);
currentprojection=orthographic((0.5,0.5,1));

drawWalk(randWalk(Gaussrand,1000,60,new pen[] {red,yellow,blue}));
shipout(bbox(3mm,Fill));

Mots-clés :


Random walk in the space – fig0060

Category: Asymptote,Examples 3D,Random Walk (3D)Ph. Ivaldi @ 16 h 46 min

Figure 0006
(Compiled with Asymptote version 1.84svn-r4619)
    
import three;
import stats;
settings.render=0;

struct walk
{
  triple[] nodes;
  pen[] p;
}

string[] dirs={"U","D","B","F","R","L"};
// U=up, D=down, B=backward, F=forward, R=right, L=left
dirs.cyclic=true;

// Comput the nodes of the path
walk randWalk(real Srnd(), int n, real angle=90, pen[] p={currentpen})
{
  p.cyclic=true;
  walk ow;
  triple udir=Z, vdir=X, kdir=cross(udir,vdir);
  triple pos=O, tpos;
  void changedir(real angle, triple axe)
  {
    transform3 T=rotate(angle,axe);
    udir=T*udir;
    vdir=T*vdir;
    kdir=T*kdir;
  }
  void nextdir()
  {
    int rd=round(Srnd());
    ow.p.push(p[rd]);
    string R=dirs[rd];
    if(R == "R") changedir(-angle,kdir);
    else if(R == "L") changedir(angle,kdir);
    else if(R == "U") changedir(angle,vdir);
    else if(R == "D") changedir(-angle,vdir);
    else if(R == "B") changedir(180,udir);
  }
  for (int i=0; i < n; ++i) {
    tpos=pos+udir;
    ow.nodes.push(tpos);
    pos=tpos;
    nextdir();
  }
  return ow;
}

walk randWalk(int Srnd(), int n, real angle=90, pen[] p={currentpen})
{
  real R(){ return Srnd();}
  return randWalk(R,n,angle,p);
}

void drawWalk(walk walk)
{
  triple camera=currentprojection.camera;
  if(currentprojection.infinity)
    camera *= max(abs(minbound(walk.nodes)),abs(maxbound(walk.nodes)));
  real[][] depth;
  for(int i=0; i < walk.nodes.length-1; ++i) {
    real d=abs(camera-0.5*(walk.nodes[i]+walk.nodes[i+1]));
    depth.push(new real[] {d,i});
  }
  depth=sort(depth);
  triple M=walk.nodes[round(depth[0][1])];
  triple m=walk.nodes[round(depth[depth.length-1][1]+1)];
  // Draw from farthest to nearest
  while(depth.length > 0) {
    real[] a=depth.pop();
    int i=round(a[1]);
    draw(walk.nodes[i]--walk.nodes[i+1],
         abs(walk.nodes[i]-m)/abs(M-m)*walk.p[i]);
  }
}


size(18cm);
currentprojection=orthographic((0.5,0.5,1));

drawWalk(randWalk(Gaussrand,10000,60,new pen[] {red,yellow,blue}));
shipout(bbox(3mm,Fill));

Mots-clés :


Random walk in the space – fig0070

Category: Asymptote,Examples 3D,Random Walk (3D)Ph. Ivaldi @ 17 h 46 min

Figure 0007
(Compiled with Asymptote version 1.84svn-r4619)
    
import three;
settings.render=0;

struct walk
{
  triple[] nodes;
  pen[] p;
}

string[] dirs={"U","D","B","F","R","L"};
// U=up, D=down, F=forward, R=right, L=left
dirs.cyclic=true;

// Comput the nodes of the path
walk randWalk(real Srnd(), int n, real angle=90, pen[] p={currentpen})
{
  p.cyclic=true;
  walk ow;
  triple udir=Z, vdir=X, kdir=cross(udir,vdir);
  triple pos=O, tpos;
  void changedir(real angle, triple axe)
  {
    transform3 T=rotate(angle,axe);
    udir=T*udir;
    vdir=T*vdir;
    kdir=T*kdir;
  }
  void nextdir()
  {
    int rd=round(Srnd());
    ow.p.push(p[rd]);
    string R=dirs[rd];
    if(R == "R") changedir(-angle,kdir);
    else if(R == "L") changedir(angle,kdir);
    else if(R == "U") changedir(angle,vdir);
    else if(R == "D") changedir(-angle,vdir);
    else if(R == "B") changedir(180,udir);
  }
  for (int i=0; i < n; ++i) {
    tpos=pos+udir;
    ow.nodes.push(tpos);
    pos=tpos;
    nextdir();
  }
  return ow;
}

walk randWalk(int Srnd(), int n, real angle=90, pen[] p={currentpen})
{
  real R(){ return Srnd();}
  return randWalk(R,n,angle,p);
}

void drawWalk(walk walk)
{
  triple camera=currentprojection.camera;
  if(currentprojection.infinity)
    camera *= max(abs(minbound(walk.nodes)),abs(maxbound(walk.nodes)));
  real[][] depth;
  for(int i=0; i < walk.nodes.length-1; ++i) {
    real d=abs(camera-0.5*(walk.nodes[i]+walk.nodes[i+1]));
    depth.push(new real[] {d,i});
  }
  depth=sort(depth);
  triple M=walk.nodes[round(depth[0][1])];
  triple m=walk.nodes[round(depth[depth.length-1][1]+1)];
  // Draw from farthest to nearest
  while(depth.length > 0) {
    real[] a=depth.pop();
    int i=round(a[1]);
    draw(walk.nodes[i]--walk.nodes[i+1],
         abs(walk.nodes[i]-m)/abs(M-m)*walk.p[i]);
  }
}


size(18cm);
currentprojection=orthographic((0.5,0.5,1));

drawWalk(randWalk(rand,10000,60,new pen[] {red,yellow,blue}));
shipout(bbox(3mm,Fill));

Mots-clés :