示例#1
0
  protected double getSegmentLength(LW2DVertex start, LW2DVertex end) {
    double l = MathUtils.distance(start.getPoint(), end.getPoint());

    if (start.getBulge() == 0.0) {
      return l;
    } else {
      double alpha = 4 * Math.atan(Math.abs(start.getBulge()));

      double r = l / (2 * Math.sin(alpha / 2));
      double d = (Math.PI * Math.toDegrees(alpha) * r) / 180;

      return d;
    }
  }
示例#2
0
  protected void addToBounds(LW2DVertex start, LW2DVertex end, Bounds bounds) {
    if (start.getBulge() != 0) {
      // calculte the height

      double l = MathUtils.distance(start.getPoint(), end.getPoint());

      // double h = Math.abs(last.getBulge()) * l / 2;
      double r = this.getRadius(start.getBulge(), l);

      double s = l / 2;
      Vector edgeDirection = MathUtils.getVector(start.getPoint(), end.getPoint());
      edgeDirection = MathUtils.normalize(edgeDirection);

      Point3D centerPoint = MathUtils.getPointOfStraightLine(start.getPoint(), edgeDirection, s);

      Vector centerPointDirection =
          MathUtils.crossProduct(edgeDirection, this.getExtrusion().getNormal());
      centerPointDirection = MathUtils.normalize(centerPointDirection);

      // double t = Math.sqrt(Math.pow(r, 2) - Math.pow(s, 2));
      // double t = 0;
      double h = Math.abs(start.getBulge() * l) / 2;

      // if(Math.abs(start.getBulge())>=1.0){
      // t = h-r;
      // }else{
      // //t = Math.sqrt(Math.pow(r, 2) - Math.pow(s, 2));
      // t=r-h;
      // }
      // the center point of the arc
      int startQ = 0;
      int endQ = 0;

      double bulge = start.getBulge();

      if (bulge > 0) {
        // the arc goes over the right side, but where is the center
        // point?
        if (bulge > 1.0) {
          double t = h - r;
          centerPoint = MathUtils.getPointOfStraightLine(centerPoint, centerPointDirection, t);
        } else {
          double t = r - h;
          centerPoint =
              MathUtils.getPointOfStraightLine(centerPoint, centerPointDirection, (-1 * t));
        }

        endQ = MathUtils.getQuadrant(end.getPoint(), centerPoint);
        startQ = MathUtils.getQuadrant(start.getPoint(), centerPoint);
      } else {
        // the arc goes over the left side, but where is the center
        // point?
        if (bulge < -1.0) {
          double t = h - r;
          centerPoint =
              MathUtils.getPointOfStraightLine(centerPoint, centerPointDirection, (-1 * t));
        } else {
          double t = r - h;
          centerPoint = MathUtils.getPointOfStraightLine(centerPoint, centerPointDirection, t);
        }

        startQ = MathUtils.getQuadrant(end.getPoint(), centerPoint);
        endQ = MathUtils.getQuadrant(start.getPoint(), centerPoint);
      }

      if (endQ < startQ) {
        endQ += 4;
      } else if ((endQ == startQ) && (Math.abs(start.getBulge()) > QUARTER_CIRCLE_ANGLE)) {
        endQ += 4;
      }

      while (endQ > startQ) {
        switch (startQ) {
          case 0:
            bounds.addToBounds(centerPoint.getX(), centerPoint.getY() + r, centerPoint.getZ());

            break;

          case 1:
            bounds.addToBounds(centerPoint.getX() - r, centerPoint.getY(), centerPoint.getZ());

            break;

          case 2:
            bounds.addToBounds(centerPoint.getX(), centerPoint.getY() - r, centerPoint.getZ());

            break;

          case 3:
            bounds.addToBounds(centerPoint.getX() + r, centerPoint.getY(), centerPoint.getZ());
            endQ -= 4;
            startQ -= 4;

            break;
        }

        startQ++;
      }
    }

    bounds.addToBounds(start.getPoint());
    bounds.addToBounds(end.getPoint());
  }