예제 #1
0
  /* CALCULATE VALUES QUADRANTS: Calculate x-y values where direction is not
  parallel to eith x or y axis. */
  public static void calcValuesQuad(int x1, int y1, int x2, int y2) {
    double arrowAng = Math.toDegrees(Math.atan((double) haw / (double) al));
    double dist = Math.sqrt(al * al + aw);
    double lineAng =
        Math.toDegrees(Math.atan(((double) Math.abs(x1 - x2)) / ((double) Math.abs(y1 - y2))));

    // Adjust line angle for quadrant
    if (x1 > x2) {
      // South East
      if (y1 > y2) lineAng = 180.0 - lineAng;
    } else {
      // South West
      if (y1 > y2) lineAng = 180.0 + lineAng;
      // North West
      else lineAng = 360.0 - lineAng;
    }

    // Calculate coords
    xValues[0] = x2;
    yValues[0] = y2;
    calcCoords(1, x2, y2, dist, lineAng - arrowAng);
    calcCoords(2, x2, y2, dist, lineAng + arrowAng);
  }
예제 #2
0
  //
  // Interface resized method.
  //
  public void resized(int width, int height) {
    double dx = eyeX - centerX;
    double dy = eyeY - centerY;
    double dz = eyeZ - centerZ;
    double d = Math.sqrt(dx * dx + dy * dy + dz * dz);

    double fovy = 2.0 * 180.0 / Math.PI * Math.atan(radius / d);
    double near = d - radius;
    double far = d + radius;

    double xUnits, yUnits;

    if (width >= height) {
      xUnits = 2 * radius * width / height;
      yUnits = 2 * radius;
    } else {
      xUnits = 2 * radius;
      yUnits = 2 * radius * height / width;
    }

    // setup projection matrix
    go.matrixMode(Go.PROJECTION);
    go.identity();
    if (perspective) {
      if (width >= height) {
        go.perspective(fovy, xUnits / yUnits, near, far);
      } else {
        double r = radius * yUnits / xUnits;
        double fovyModified = Math.atan(r / d) * 180.0 / Math.PI * 2.0;
        go.perspective(fovyModified, xUnits / yUnits, near, far);
      }
    } else {
      go.ortho(-xUnits / 2.0, xUnits / 2.0, -yUnits / 2.0, yUnits / 2.0, near, far);
    }
    go.matrixMode(Go.MODELVIEW);
  }
예제 #3
0
 public static void drawLine(Graphics g, int x1, int y1, int x2, int y2, int lineWidth) {
   if (lineWidth == 1) g.drawLine(x1, y1, x2, y2);
   else {
     double angle;
     double halfWidth = ((double) lineWidth) / 2.0;
     double deltaX = (double) (x2 - x1);
     double deltaY = (double) (y2 - y1);
     if (x1 == x2) angle = Math.PI;
     else angle = Math.atan(deltaY / deltaX) + Math.PI / 2;
     int xOffset = (int) (halfWidth * Math.cos(angle));
     int yOffset = (int) (halfWidth * Math.sin(angle));
     int[] xCorners = {x1 - xOffset, x2 - xOffset + 1, x2 + xOffset + 1, x1 + xOffset};
     int[] yCorners = {y1 - yOffset, y2 - yOffset, y2 + yOffset + 1, y1 + yOffset + 1};
     g.fillPolygon(xCorners, yCorners, 4);
   }
 }