Class Stripes – the code

// a class for working with stripes/sets of parallel lines
// lines defined ba ax+by=shift+k; where k is integer

// this makes sets of parallel lines as 
//  used in "projection method-geometry and maths"

// see the post "How to shift the design" for translations by (xTrans,yTrans)

class Stripes{
  float a,b,shift;
  int kmax;

  Stripes(float angle,float sp){
    a=cos(angle);
    b=sin(angle);
    shift=sp+a*xTrans+b*yTrans;
    shift=shift-floor(shift);
    // determine lines ax+by=c at corners of screen - maximum value for kmax=c-shift
    kmax=2*int(abs(a)*xRange+abs(b)*yRange)+2;
  }
  
// get k-value (real number) for a given point (class Vector) p
float getK(Vector p){
  return a*p.x+b*p.y-shift;
}
  

//  get intersection with  line of other stripe set with choosen k-values
Vector intersection(Stripes stripe,int k,int ki){
  float x,y,den;
  den=1./(a*stripe.b-b*stripe.a);
  x=den*((shift+k)*stripe.b-b*(stripe.shift+ki));
  y=den*(a*(stripe.shift+ki)-(shift+k)*stripe.a);
  return new Vector(x,y);
}
}
This entry was posted in programming and tagged , , . Bookmark the permalink.

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