Exemplo n.º 1
0
  /**
   * segment curve
   *
   * @param p1
   * @param p2
   */
  public void segment(GgbVector p1, GgbVector p2) {

    length = (float) p1.distance(p2);
    if (Kernel.isEqual(length, 0, Kernel.STANDARD_PRECISION)) return;

    down(p1);

    switch (arrowType) {
      case ARROW_TYPE_NONE:
      default:
        setTextureX(0, 1);
        moveTo(p2);
        break;
      case ARROW_TYPE_SIMPLE:
        float factor = (12 + lineThickness) * LINE3D_THICKNESS / scale;
        float arrowPos = ARROW_LENGTH / length * factor;
        GgbVector arrowBase = (GgbVector) start.getCenter().mul(arrowPos).add(p2.mul(1 - arrowPos));

        setTextureX(0);
        if (hasTicks()) {
          GgbVector d = p2.sub(p1).normalized();
          float thickness = this.thickness;

          float i =
              ticksOffset * length - ((int) (ticksOffset * length / ticksDistance)) * ticksDistance;
          float ticksDelta = thickness;
          float ticksThickness = 4 * thickness;
          if (i <= ticksDelta) i += ticksDistance;

          for (; i <= length * (1 - arrowPos); i += ticksDistance) {

            GgbVector p1b = (GgbVector) p1.add(d.mul(i - ticksDelta));
            GgbVector p2b = (GgbVector) p1.add(d.mul(i + ticksDelta));

            setTextureType(TEXTURE_AFFINE);
            setTextureX(i / length);
            moveTo(p1b);
            setThickness(ticksThickness);
            setTextureType(TEXTURE_CONSTANT_0);
            moveTo(p1b);
            moveTo(p2b);
            setThickness(thickness);
            moveTo(p2b);
          }
        }

        setTextureType(TEXTURE_AFFINE);
        setTextureX(1 - arrowPos);
        moveTo(arrowBase);

        textureTypeX = TEXTURE_ID;
        setTextureX(0, 0);
        setThickness(factor * ARROW_WIDTH);
        moveTo(arrowBase);
        setThickness(0);
        moveTo(p2);
        break;
    }
  }
Exemplo n.º 2
0
  /**
   * adds the point with the specified position and tangent to the curve currently being drawn.
   *
   * @param p the point's position vector
   * @param t the tangent at the point
   */
  public void addPointToCurve3D(GgbVector3D p, GgbVector3D t) {
    GgbVector position = new GgbVector(p.getX(), p.getY(), p.getZ(), 0);
    GgbVector tangent = new GgbVector(t.getX(), t.getY(), t.getZ(), 0);
    if (firstCurvePoint) {
      end = new PlotterBrushSection(position, tangent, thickness);
      firstCurvePoint = false;
    } else {
      if (discontinuityPassed(position)) {
        startDrawingCurve(); // start drawing a new segment
        addPointToCurve(position, tangent);
        return;
      } else {
        start = end;
        end = new PlotterBrushSection(start, position, tangent, thickness);

        addCurvePos((float) position.sub(start.getCenter()).norm());
        join();
      }
    }
    previousPosition = position;
    previousTangent = tangent;
  }
 /** set the matrix to [V O] */
 public void setCoordFromPoints(GgbVector a_O, GgbVector a_I) {
   setCoord(a_O, a_I.sub(a_O));
 }
Exemplo n.º 4
0
  /**
   * A test used to judge if the curve has passed over a discontinuity since the last point was
   * added.
   *
   * @param position the position of the new point (pos2)
   * @return true iff (pos2-pos1)/||pos2-pos1|| . tangent1 < CurveTree.discontinuityThreshold
   */
  private boolean discontinuityPassed(GgbVector position) {
    GgbVector dir = position.sub(previousPosition).normalized();

    if (dir.dotproduct(previousTangent) < CurveTree.discontinuityThreshold) return true;
    return false;
  }