Projection method for 5-fold rotational symmetry – the code

// ********* use processing 2 **************** you can download from processing.org
//------------------------------------------------------------------------------------
// this is the main code to generate the image of the previous post
// and other related quasiperiodic designs
// it is similar to the one shown in "projection methods with polygons - the code"
// 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"

//---------------------------------------------------------------------------------------------------------
//***********BE PATIENT this program takes a lot of time before it shows anything*******
//---------------------------------------------------------------------------------------------------------

float unitLength;
float xRange,yRange;     // visible coordinates from -(xy)Range to +(xy)Range
Stripes[] allStripes;
int numDirections;
float xTrans,yTrans;
float small,lineLengthSquare;
Tiling tiling;


void setup(){
  size(600,600);
  smooth();
  unitLength=5;
  setupCoordinates();
  xRange*=1.1;
  yRange*=1.1;
  vectorDiameter=6/unitLength;
  ellipseMode(CENTER);
  small=0.01;
  tiling=new Tiling();
  numDirections=5;
  //  --------------    above determines symmetry
  xTrans=40;
  yTrans=40;
  // above defines translation
  allStripes=new Stripes[numDirections];
  float alfa=2*PI/numDirections;
  float s=0.42;   // try 0.33
  for(int i=0;i<numDirections;i++){
    allStripes[i]=new Stripes(i*alfa,s);
  }
}

void draw(){
  noLoop();
  doTransformations();   // attention: translate and scale are reset at start of draw
  background(color(255,255,255));
  noStroke();
  testPoints();
  lineLengthSquare=tiling.minDistanceSquare();
  lineLengthSquare*=sq(0.5/sin(PI/2/numDirections));
  //  use this above if you have rhombs
  tiling.generateLines(lineLengthSquare);
  tiling.sortConnections(); 
  fill(color(175,0,255));
  tilingShowRegularPolygons(5);   
  fill(color(255,0,0,70));
  tilingShowOverlapRhombs(PI/5);
  fill(color(230,128,150));
  tilingShowRegularPolygons(10); 
  stroke(100,50,0);
  trueStrokeWeight(1.5);
  tiling.showConnections();
//  tilingShowPointsWithoutPolygons();
  println("fertig");
//  saveImage();
}

//  test all possible points
void testPoints(){
  int k0,k1;
  int k0Max=allStripes[0].kmax;
  int k1Max=allStripes[1].kmax;
  for(k0=-k0Max;k0 < k0Max;k0++){
    for(k1=-k1Max;k1 < k1Max;k1++){
        test(k0,k1);
    }
  }
}

//show upper and lower linits of stripes at an intersection point
//  and points of star


void test(int k1,int km){
  Vector v;
  Vector[] starPoints=new Vector[numDirections];
  int[] kLow=new int[numDirections];
  int i,j;
  trueStrokeWeight(3);
  v=allStripes[1].intersection(allStripes[numDirections-1],k1,km);
  starPoints[0]=v;
  //  determine k-values
  kLow[1]=k1;
  kLow[numDirections-1]=km;
  kLow[0]=floor(allStripes[0].getK(v));
  for (i=2;i < numDirections-1;i++){
    kLow[i]=floor(allStripes[i].getK(v))+1;
  }
 
  for (i=1;i < numDirections-1;i++){
    starPoints[i]=allStripes[i+1].intersection(allStripes[i-1],kLow[i+1],kLow[i-1]);
  }
  starPoints[numDirections-1]=allStripes[0].intersection(allStripes[numDirections-2],kLow[0],kLow[numDirections-2]);

  // test
  float kMinusKLow;
  // starPoint[0] is at a good position because of the choice of stripes
  for( i=1;i<numDirections;i++){   //  check conditions, return upon failure and do nothing
    kMinusKLow=allStripes[i].getK(starPoints[i])-kLow[i];
    if(kMinusKLow > 1)  return;
    if(kMinusKLow < 0)  return;
  }
  for( i=1;i<numDirections-1;i++){  //  skipping  j=i-1,i,i+1
    for (j=0;j < i-1;j++){
     kMinusKLow=allStripes[j].getK(starPoints[i])-kLow[j];
     if(kMinusKLow > 0) return;
     if(kMinusKLow < -1) return;     
    }
    for (j=i+2;j < numDirections;j++){
     kMinusKLow=allStripes[j].getK(starPoints[i])-kLow[j];
     if(kMinusKLow > 0) return;
     if(kMinusKLow < -1) return;     
    }
  }
  for(j=1;j < numDirections-2;j++){
    kMinusKLow=allStripes[j].getK(starPoints[numDirections-1])-kLow[j];
    if(kMinusKLow > 0) return;
    if(kMinusKLow < -1) return;
  }
  // get center=average of all points
  Vector center=new Vector(starPoints[0]);
  for (i=1;i < numDirections;i++){
    center.add(starPoints[i]);
  }
  center.mult(1.0/numDirections);
  tiling.add(new TPoint(center));
}
This entry was posted in programming, Quasiperiodic design, Tilings and tagged , , , , . Bookmark the permalink.

One Response to Projection method for 5-fold rotational symmetry – the code

  1. Eric says:

    I’m very glad you’re returning to your series on code for aperiodic tiling.

    The comment preceding the code above has a minor omission: to get the above code to run, the code from https://geometricolor.wordpress.com/2013/09/27/overlapping-polygons-the-code/ must also be included.

    I’m interested in generating aperiodic tilings without any gaps and without any overlapping tiles. I confess I haven’t studied the code you’ve recently been posting, because I figured I’d wait for the entire program and then work backwards. But maybe I’m missing something. Can the code you’ve posted so far already generate aperiodic tilings without gaps and overlapping tiles, or is still more code needed for that? Thanks!

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