Exemple #1
0
  /*======== public void addCurve() ==========
      Inputs:   int x0
                int y0
  int x1
  int y1
  int x2
  int y2
  int x3
  int y3
      Returns:

      Generates the edges required to create a curve
      and adds them to the edge matrix

      03/09/12 18:00:06
      jonalf
      ====================*/
  public void addCurve(
      double x0,
      double y0,
      double x1,
      double y1,
      double x2,
      double y2,
      double x3,
      double y3,
      int type) {

    EdgeMatrix xcoefs = new EdgeMatrix(1);
    EdgeMatrix ycoefs = new EdgeMatrix(1);

    // a lower step value makes a more precise curve
    double step = 0.01;

    double x, y, z, ax, ay, bx, by, cx, cy, dx, dy;

    if (type == gui.HERMITE_MODE) {
      xcoefs.generateHermiteCoefs(x0, x1, x2, x3);
      ycoefs.generateHermiteCoefs(y0, y1, y2, y3);
    } else {
      xcoefs.generateBezierCoefs(x0, x1, x2, x3);
      ycoefs.generateBezierCoefs(y0, y1, y2, y3);
    }

    ax = xcoefs.getX(0);
    bx = xcoefs.getY(0);
    cx = xcoefs.getZ(0);
    dx = xcoefs.getD(0);

    ay = ycoefs.getX(0);
    by = ycoefs.getY(0);
    cy = ycoefs.getZ(0);
    dy = ycoefs.getD(0);

    double startx = x0;
    double starty = y0;

    for (double t = step; t <= 1; t += step) {

      x = ax * t * t * t + bx * t * t + cx * t + dx;
      y = ay * t * t * t + by * t * t + cy * t + dy;

      addEdge(startx, starty, 0, x, y, 0);
      startx = x;
      starty = y;
    }
  }