/* Usage of this class -
   VHead head = new VHead2(double,startx, starty, endx, endy);
   g.fillPolygon(head.xpoints(), head.ypoints(), head.npoints()); */

class VHead2 {
  private double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0;
  private double scale = 1;
  private double t; //angle, theta
  private double ax1 = -10.0, ay1 = 4.0, ax2 = -10.0, ay2 = -4.0;

  //default constructor
  public VHead2() {
  this.x1=0.0; this.y1=0.0; this.x2=0.0; this.y2=0.0;
  this.scale = 1;
  this.ax1 = -10.0*scale; this.ay1 = 4.0*scale; 
  this.ax2 = -10.0*scale; this.ay2 = -4.0*scale;
  }

  //constructor
  public VHead2(double fscale, int fx1, int fy1, int fx2, int fy2) {
    this.x1 = (double)fx1;
    this.y1 = -(double)fy1;
    this.x2 = (double)fx2;
    this.y2 = -(double)fy2;
    this.scale = fscale;
    this.ax1 = -10.0*scale; this.ay1 = 4.0*scale;
    this.ax2 = -10.0*scale; this.ay2 = -4.0*scale;
  }

  //method to return array of x values
  public int[] xpoints() {
    int xArray[] = new int[3];

    //compute value of theta
    t = Math.abs(Math.atan((double)(y2-y1)/(x2-x1)));
    if ((x2<x1) & (y2>=y1)) t = (Math.PI)-t;
    else if ((x2<x1) & (y2<y1)) t = (Math.PI)+t;
    else if ((x2>=x1) & (y2<y1)) t = (2*Math.PI)-t;

    //set first value to be same as second (end) point of vector
    xArray[0] = (int)x2;

    xArray[1] = (int)(x2 + Math.cos(t)*ax1 - Math.sin(t)*ay1);
    xArray[2] = (int)(x2 + Math.cos(t)*ax2 - Math.sin(t)*ay2);
    return xArray;
  }


  //method to return array of y values
  public int[] ypoints() {
    int yArray[] = new int[3];

    //set first value to be same as second (end) point of vector
    yArray[0] = -(int)y2;

    yArray[1] = -(int)(y2 + Math.sin(t)*ax1 + Math.cos(t)*ay1);
    yArray[2] = -(int)(y2 + Math.sin(t)*ax2 + Math.cos(t)*ay2);
    return yArray;
  }

  //method to return number of points i.e. 3 for a triangle
  public int npoints() {
    return 3;
  }
}

