import java.awt.*;
public class Arrows {

  public static void drawUpArrow(Graphics imG, int x, int y) {
    int[] arrowXPts = new int[3];
    int[] arrowYPts = new int[3];
    arrowXPts[0] = x;    arrowYPts[0] = y-1;
    arrowXPts[1] = x-3;  arrowYPts[1] = y+6;
    arrowXPts[2] = x+3;  arrowYPts[2] = y+6;
    imG.fillPolygon(arrowXPts,arrowYPts,3);
  }
  public static void drawDblUpArrow(Graphics imG, int x, int y, double sfactor) {
    double s;
    s = sfactor;
    int[] arrowXPts = new int[3];
    int[] arrowYPts = new int[3];
    arrowXPts[0] = x;    arrowYPts[0] = y;
    arrowXPts[1] = x-(int)(s*4);  arrowYPts[1] = y+(int)(s*10);
    arrowXPts[2] = x+(int)(s*4);  arrowYPts[2] = y+(int)(s*10);
    imG.fillPolygon(arrowXPts,arrowYPts,3);
  }
  public static void drawDownArrow(Graphics imG, int x, int y) {
    int[] arrowXPts = new int[3];
    int[] arrowYPts = new int[3];
    arrowXPts[0] = x;    arrowYPts[0] = y;
    arrowXPts[1] = x-3;  arrowYPts[1] = y - 6;
    arrowXPts[2] = x+3;  arrowYPts[2] = y - 6;
    imG.fillPolygon(arrowXPts,arrowYPts,3);
  }
  public static void drawDblDownArrow(Graphics imG, int x, int y, double sfactor) {
    double s;
    s = sfactor;
    
    int[] arrowXPts = new int[3];
    int[] arrowYPts = new int[3];
    arrowXPts[0] = x;    arrowYPts[0] = y;
    arrowXPts[1] = x-(int)(s*4);  arrowYPts[1] = y - (int)(s*10);
    arrowXPts[2] = x+(int)(s*4);  arrowYPts[2] = y - (int)(s*10);
    imG.fillPolygon(arrowXPts,arrowYPts,3);
  }
  public static void drawRightArrow(Graphics imG, int x, int y) {
    int[] arrowXPts = new int[3];
    int[] arrowYPts = new int[3];
    arrowXPts[0] = x;    arrowYPts[0] = y;
    arrowXPts[1] = x-6;  arrowYPts[1] = y - 3;
    arrowXPts[2] = x-6;  arrowYPts[2] = y + 3;
    imG.fillPolygon(arrowXPts,arrowYPts,3);
  }
  public static void drawDblRightArrow(Graphics imG, int x, int y, double sfactor) {
    double s;
    s = sfactor;

    int[] arrowXPts = new int[3];
    int[] arrowYPts = new int[3];
    arrowXPts[0] = x;    arrowYPts[0] = y;
    arrowXPts[1] = x-(int)(s*10);  arrowYPts[1] = y - (int)(s*4);
    arrowXPts[2] = x-(int)(s*10);  arrowYPts[2] = y + (int)(s*4);
    imG.fillPolygon(arrowXPts,arrowYPts,3);
  }
  public static void drawLeftArrow(Graphics imG, int x, int y) {
    int[] arrowXPts = new int[3];
    int[] arrowYPts = new int[3];
    arrowXPts[0] = x;    arrowYPts[0] = y;
    arrowXPts[1] = x+6;  arrowYPts[1] = y - 3;
    arrowXPts[2] = x+6;  arrowYPts[2] = y + 3;
    imG.fillPolygon(arrowXPts,arrowYPts,3);
  }
  public static void drawDblLeftArrow(Graphics imG, int x, int y, double sfactor) {
    double s;
    s = sfactor;

    int[] arrowXPts = new int[3];
    int[] arrowYPts = new int[3];
    arrowXPts[0] = x;    arrowYPts[0] = y;
    arrowXPts[1] = x+(int)(s*10);  arrowYPts[1] = y - (int)(s*4);
    arrowXPts[2] = x+(int)(s*10);  arrowYPts[2] = y + (int)(s*4);
    imG.fillPolygon(arrowXPts,arrowYPts,3);
  }
  public static double PIOverOneEighty = Math.PI/180.0;

  //public static Point[] getArrowHeadPts(Point endPt, Point startPt) {
  //  return getArrowHeadPts(endPt.x, endPt.y, startPt.x, startPt.y);
  //}

  public static Point[] getArrowHeadPts(int xEndPt, int yEndPt,
                                        int xStartPt, int yStartPt) {
    Point[] pts = new Point[3];
    int[] xPts = new int[3];
    int[] yPts = new int[3];
    double x, y;
    double xArrowComponent, yArrowComponent;
    double arrowDeltaX, arrowDeltaY;

    double phi = Math.atan2(-1.0*(yEndPt-yStartPt),(xEndPt-xStartPt));

    xArrowComponent = Math.sin(phi)*3.5;
    yArrowComponent = Math.cos(phi)*3.5;
    arrowDeltaX = Math.cos(phi)*7.0;
    arrowDeltaY = Math.sin(phi)*7.0;

    xPts[2] = xEndPt;
    yPts[2] = yEndPt;
    x = xEndPt - arrowDeltaX;
    y = yEndPt + arrowDeltaY;
    xPts[0] = (int) (x - xArrowComponent);
    xPts[1] = (int) (x + xArrowComponent);
    yPts[0] = (int) (y - yArrowComponent);
    yPts[1] = (int) (y + yArrowComponent);
    for (int j = 0; j < pts.length; j++)
      pts[j] = new Point(xPts[j],yPts[j]);
    return pts;
  }

  //public static Point[] getDblArrowHeadPts(Point endPt, Point startPt) {
  //  return getDblArrowHeadPts(endPt.x, endPt.y, startPt.x, startPt.y);
  //}

  public static Point[] getDblArrowHeadPts(int xEndPt, int yEndPt,
                                           int xStartPt, int yStartPt, double sfactor) {
    Point[] pts = new Point[3];
    int[] xPts = new int[3];
    int[] yPts = new int[3];
    double x, y;
    double xArrowComponent, yArrowComponent;
    double arrowDeltaX, arrowDeltaY;

    double phi = Math.atan2(-1.0*(yEndPt-yStartPt),(xEndPt-xStartPt));

    xArrowComponent = Math.sin(phi)*sfactor*4.5;
    yArrowComponent = Math.cos(phi)*sfactor*4.5;
    arrowDeltaX = Math.cos(phi)*sfactor*9.0;
    arrowDeltaY = Math.sin(phi)*sfactor*9.0;

    xPts[2] = xEndPt;
    yPts[2] = yEndPt;
    x = xEndPt - arrowDeltaX;
    y = yEndPt + arrowDeltaY;
    xPts[0] = (int) (x - xArrowComponent);
    xPts[1] = (int) (x + xArrowComponent);
    yPts[0] = (int) (y - yArrowComponent);
    yPts[1] = (int) (y + yArrowComponent);
    for (int j = 0; j < pts.length; j++)
      pts[j] = new Point(xPts[j],yPts[j]);
    return pts;
  }

  public static void drawArrowHead(Graphics imG, Point[] pts) {
    int[] xArrow = new int[3];
    int[] yArrow = new int[3];
    for (int i = 0; i < pts.length && i < 3; i++) {
      xArrow[i] = pts[i].x;
      yArrow[i] = pts[i].y;
    }
    imG.fillPolygon(xArrow,yArrow,3);
  }


  public static void drawArrowHead(Graphics imG,
                             int[] xArrow, int[] yArrow) {
    imG.fillPolygon(xArrow,yArrow,3);
  }


  public static Point getEndPoint(Point startPoint, int degrees, int len) {
    double phi = degrees * PIOverOneEighty;
    return getEndPoint(startPoint,phi,len);
  }

  public static Point getEndPoint(Point startPoint, double phi, int len) {
    int deltaX = (int)(Math.cos(phi)*len);
    int deltaY = (int)(Math.sin(phi)*len);
    Point endPt = new Point(startPoint.x + deltaX, startPoint.y - deltaY);
    return endPt;
  }

}
