Projection method for the Stampfli and the Socolar tiling – the code

// ********* use processing 2 **************** you can download from processing.org
//------------------------------------------------------------------------------------
// this is the main code to generate the stampfli and the socolar tiling
// and other related quasiperiodic designs
// put this code in the main tab of processing at the left
// requires the code of "finding polygons - the code",
// "class stripes - the code", "setting up the coordinates - the modified code",
// "class Tiling - the code", "class TPoint - the code",
// "class Vector - the code" and "saving images - the code"

//--------------------------------------------------------------

float unitLength;
float xRange,yRange;     // visible coordinates from -(xy)Range to +(xy)Range
float sqrt2=sqrt(2.),sqrt05=sqrt(0.5),rt3=sqrt(3.);;
float xShift,yShift;     //  shifting one grid to get different parts of the tiling
float small,lineLenghtSquare;
float modification;
Tiling tiling;


void setup(){
  size(700,600);
  smooth();
  background(255);
  unitLength=2;
  setupCoordinates();
  xRange*=0.5;
  yRange*=0.5;
  xShift=0.5500;
  yShift=0.800;
  modification=1;       //  for the stampfli tiling, with rhombs
 // modification=rt3;       //  for the shield tiling, without rhombs
  ellipseMode(CENTER);
  small=0.01;
  tiling=new Tiling();
}

void draw(){
  noLoop();
  doTransformations();
  trueStrokeWeight(1.5);

  background(255);
  fill(0,255,0);
  stroke(0);

  hexagonKombination();

  lineLenghtSquare=tiling.minDistanceSquare();
  lineLenghtSquare*=sq(0.5/sin(PI/12));                   //  this is only for rhombs !!!!(stampfli tiling)
  generateDodecaLines(tiling,lineLenghtSquare);
  tiling.sortConnections();
  fill(color(0,0,255));
  tilingShowRegularPolygons(3);   
  fill(color(255,0,0));
  tilingShowRegularPolygons(4);   
 // saveImage();
}

  void hexagonKombination() {
    int i1, j1, i2, j2;
    float x1, y1, x2, y2; 
    float xm, ym, dx, dy, h;
    Vector v;
    int  limit=int(xRange*2);
    for (i1=-limit; i1<limit; i1++) {
      y1=i1*1.5+yShift;
      for (j1=-limit;j1<limit;j1++) {
        x1=(j1*rt3+(i1 % 2)*rt3/2)+xShift;
        i2=round(x1*2/3);
        j2=round(y1/rt3-0.5*(i2 % 2));
        x2=i2*1.5;
        y2=j2*rt3+rt3/2*(i2 % 2);
        dx=abs(x1-x2);
        dy=abs(y1-y2);
        if (dy>dx) {
          h=dx;
          dx=dy;
          dy=h;
        }
        if ((dx<(1-rt3*0.5)*modification)&&((dx*rt3+dy)<(2-rt3)*modification)) {
          xm=(x1+x2)/2;
          ym=(y1+y2)/2;
           v=new Vector(xm,ym);
           tiling.add(new TPoint(v));
        }
      }
    }
  }
  //generate lines with special catch
  
    //generate lines of given length (squared)
  //  saved as connections between tiling points
    void generateDodecaLines(Tiling tiling,float lineLengthSquare){
    int i,j,k;
    float catchLengthSquare=0.1*lineLengthSquare;
    boolean ok;
    Vector midPoint;
    for(i=0;i<tiling.points.length-1;i++){
      for(j=i+1;j<tiling.points.length;j++){
        if(abs(tiling.distanceSquare(i,j)-lineLengthSquare)<small){
          // check if line is too close to tilingpoint
          ok=true;
          midPoint=interpolate(0.5,tiling.points[j].vec,tiling.points[i].vec);
          for (k=0;k<tiling.points.length;k++){                            //  omit line if a point is too close
            if( (sq(tiling.points[k].vec.x-midPoint.x)                     // Vector.sq() function missing
            +sq(tiling.points[k].vec.y-midPoint.y))<catchLengthSquare){
              ok=false;                                   // do not draw line across rhombs
              break;
            }
          }
          if(ok){
            tiling.points[i].addConnection(tiling.points[j]);
            tiling.points[j].addConnection(tiling.points[i]);
          }
        }
      }
    }
  }
This entry was posted in programming, Quasiperiodic design, Tilings and tagged , , , , . Bookmark the permalink.

One Response to Projection method for the Stampfli and the Socolar tiling – the code

  1. Eric says:

    Terrific!

    If I’m not missing something, the code above produces the Stampfli tiling, but the rhombs aren’t filled in. Since I’m interested in tilings without gaps, I added a new tab with the overlapping polygons code from https://geometricolor.wordpress.com/2013/09/27/overlapping-polygons-the-code/ and then I included the following two lines to draw(), at the end of the function:
    fill(color(255,255,0));
    tilingShowOverlapRhombs(PI/6);
    The rhombs don’t overlap, so tilingShowOverlapRhombs simply fills them in.

    I’m quite happy about this — I originally came to this blog a number of months ago because I saw a reference to the “Stampfli tiling” on John Savard’s tiling webpage here: http://www.quadibloc.com/math/dode02.htm, and yet I didn’t see any reference to the “Stampfli tiling” mentioned in the Tiling Encyclopedia here: ttp://tilings.math.uni-bielefeld.de/. The Tiling Encyclopedia lists substitution rules, and I was disappointed (and then intrigued) to learn on this blog that the Stampfli tiling can’t be generated with substitution rules — other readers should see https://geometricolor.wordpress.com/2012/09/29/finding-an-iteration-method-for-the-stampfli-tiling-mission-impossible/

    So, finally getting code for the Stampfli tiling, (and without gaps or overlaps), is very satisfying. I’ll share a webpage showing what I’m doing with the Stampfli tiling in the near future, as soon as it is ready. By the way, as I searched the web for references to the Stampfli tiling, it only slowly dawned on me that this blog is by Peter Stampfli himself! Thank you again for this blog. The material here would make for an excellent book.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s