Examples of CubicCurve2D


Examples of java.awt.geom.CubicCurve2D

  protected void basicMoveBy(int dx, int dy)
  {
    // Don't move the start and end point since they are connected
    for (Iterator it = segments.iterator(); it.hasNext();)
    {
      CubicCurve2D next = (CubicCurve2D) it.next();

      next.setCurve(next.getX1() + dx, next.getY1() + dy, next.getCtrlX1() + dx, next.getCtrlY1() + dy, next.getCtrlX2() + dx, next.getCtrlY2() + dy, next.getX2() + dx, next.getY2() + dy);
    }
  }
View Full Code Here

Examples of java.awt.geom.CubicCurve2D

    Point2D target = new Point2D.Double(2f * center.getX() - p.getX(), 2f * center.getY() - p.getY());

    if (side == 0)
    {
      // We modify CtrlP1
      CubicCurve2D next = (CubicCurve2D) segments.get(index);

      next.setCurve(next.getP1(), target, next.getCtrlP2(), next.getP2());
    }
    else
    {
      // We modify CtrlP2
      CubicCurve2D prev = (CubicCurve2D) segments.get(index - 1);

      prev.setCurve(prev.getP1(), prev.getCtrlP1(), target, prev.getP2());
    }
  }
View Full Code Here

Examples of java.awt.geom.CubicCurve2D

    dy = CommonUtil.rnd(target.getY() - p.getY());

    if (index > 0)
    {
      // if index is not the first segment, we adjust the endpoint of the previous segment
      CubicCurve2D prev = (CubicCurve2D) segments.get(index - 1);

      p = prev.getCtrlP2();

      p.setLocation(p.getX() + dx, p.getY() + dy);

      prev.setCurve(prev.getP1(), prev.getCtrlP1(), p, target);

      basicSetCtrlPoint(index, LEFT_CONTROLPOINT, p);
    }
    if (index < segments.size())
    {
      // likewise, if we are not the last segment, we adjust the position of the one after us

      CubicCurve2D next = (CubicCurve2D) segments.get(index);

      p = next.getCtrlP1();

      p.setLocation(p.getX() + dx, p.getY() + dy);

      next.setCurve(target, p, next.getCtrlP2(), next.getP2());

      basicSetCtrlPoint(index, RIGHT_CONTROLPOINT, p);
    }

    changed();
View Full Code Here

Examples of java.awt.geom.CubicCurve2D

    target = constrainCtrlPoint(index, side, target);

    if (side != LEFT_CONTROLPOINT)
    {
      // We modify CtrlP1
      CubicCurve2D next = (CubicCurve2D) segments.get(index);
      next.setCurve(next.getP1(), target, next.getCtrlP2(), next.getP2());
    }
    else
    {
      // We modify CtrlP2
      CubicCurve2D prev = (CubicCurve2D) segments.get(index - 1);
      prev.setCurve(prev.getP1(), prev.getCtrlP1(), target, prev.getP2());
    }
  }
View Full Code Here

Examples of java.awt.geom.CubicCurve2D

    {
      // - we remove the segment AFTER the given point
      // - we set the end point of the segment before the given point
      //   to the start point of the segment after the deleted segment

      CubicCurve2D removed = (CubicCurve2D) segments.remove(i);
      CubicCurve2D prev = (CubicCurve2D) segments.get(i - 1);

      prev.setCurve(prev.getP1(), prev.getCtrlP1(), removed.getCtrlP2(), removed.getP2());
    }

    changed();
    clearShapeCache();
  }
View Full Code Here

Examples of java.awt.geom.CubicCurve2D

    // we normalize the position to the number of segments
    position = position * segments.size();

    // We get the appropriate segment
    CubicCurve2D curve = (CubicCurve2D) segments.get(Math.min(segments.size() - 1, (int) Math.floor(position)));

    position %= 1;

    double k1, k2, k3, k4;

    k1 = (1 - position) * (1 - position) * (1 - position);
    k2 = (1 - position) * (1 - position) * position * 3;
    k3 = (1 - position) * position * position * 3;
    k4 = position * position * position;

    ret.setLocation(k1 * curve.getX1() + k2 * curve.getCtrlX1() + k3 * curve.getCtrlX2() + k4 * curve.getX2(), k1 * curve.getY1() + k2 * curve.getCtrlY1() + k3 * curve.getCtrlY2() + k4 * curve.getY2());

    return ret;
  }
View Full Code Here

Examples of java.awt.geom.CubicCurve2D

    // find the segment to this coordinates
    int i = findSegment(x, y);

    if (i != -1)
    {
      CubicCurve2D insert = new CubicCurve2D.Double();

      CubicCurve2D prev = ((CubicCurve2D) segments.get(i));

      prev.subdivide(prev, insert);

      segments.add(i + 1, insert);

      setPointAt(i + 1, new Point(x, y));
View Full Code Here

Examples of org.codemap.util.geom.CubicCurve2D

        fourPoints[1] = parent;
        fourPoints[2] = child;
        fourPoints[3] = grandChild;

        Shape shape = edge.getShape();
        CubicCurve2D myCurve;
        if (shape == null) {
            myCurve = new CubicCurve2D.Double();
            edge.setShape(myCurve);
        } else {
            myCurve = (CubicCurve2D)shape;
        }
       
        BezierSpline.computeOneSpline(grandParent, parent, child, grandChild, myCurve);

        // 11. Now do some tweaking of the control points to ensure continuity.
        // need to tweak the first control point to be collinear with the parent
        // and the grandparent and have the same distance as the
        // parent-grandparent
        double parentGrandDist = grandParent.distance(parent);

        Vector2D grandToParent = new Vector2D(grandParent, parent);
        //System.out.println(grandToParent);
        //now take the grandToParent vector, scale by parentGrandDistance, add
        // it to the parent vector
       
          Point2D collinShift = new Point2D.Double(parentGrandDist
                * grandToParent.getNormalized().getX() + parent.getX(),
                parentGrandDist * grandToParent.getNormalized().getY()
                        + parent.getY());
        //System.out.println("before: " + myCurve.getP1() + ", "
        // +myCurve.getCtrlP1() + ", " + myCurve.getCtrlP2() + ", " +
        // myCurve.getP2() );
        myCurve.setCurve(myCurve.getP1(), collinShift, myCurve.getCtrlP2(),
                myCurve.getP2());
        GraphicsGems.checkNaN(myCurve.getP1());
        GraphicsGems.checkNaN(myCurve.getP2());
        GraphicsGems.checkNaN(myCurve.getCtrlP1());
        GraphicsGems.checkNaN(myCurve.getCtrlP2());
       
        //System.out.println("after: " + myCurve.getP1() + ", "
        // +myCurve.getCtrlP1() + ", " + myCurve.getCtrlP2() + ", " +
        // myCurve.getP2() );

        //System.out.println("CollinShift dist: " +
        // collinShift.distance(parent) + " and p-GP dist: " + parentGrandDist);

        // 10. Need to set the previous control point for the child node
        Node otherItem = edge.getSecondNode();
        otherItem.setPrevControlPoint(myCurve.getCtrlP2());

        //System.out.println("Prev Control Point for " +
        // ((FlowNode)otherItem.getEntity()).toStringId() + " was set to prev
        // control point: " + grandParent);
       
        if ((m_additiveEdges) && (shiftPoint != null)) {
           
       
            // 12. Now shift the bezier points to line up properly with the horizontal translation
            // that takes into account the thickness of the curve. We do this by shifting
            // the first two points of every bezier to get it to line up in the appropriate place
            Point2D grandParentShift = new Point2D.Double(myCurve.getP1().getX()+shiftPoint.getX(),
                myCurve.getP1().getY()+shiftPoint.getY());
            Point2D parentShift = new Point2D.Double(myCurve.getCtrlP1().getX()+shiftPoint.getX(),
                myCurve.getCtrlP1().getY()+shiftPoint.getY());
            myCurve.setCurve(grandParentShift, parentShift, myCurve.getCtrlP2(), myCurve.getP2());
        }
        GraphicsGems.checkNaN(myCurve.getP1());
        GraphicsGems.checkNaN(myCurve.getP2());
        GraphicsGems.checkNaN(myCurve.getCtrlP1());
        GraphicsGems.checkNaN(myCurve.getCtrlP2());

        return displayWidth;
    }   
View Full Code Here

Examples of org.codemap.util.geom.CubicCurve2D

    // given a list of points to interpolate through (catmull rom points),
    // returns a List
    // of CubicCurve2D objects with the curves to interpolate through
    public static Collection<CubicCurve2D> computeSplines(Point2D[] points) {
        List<CubicCurve2D> newCubics = new ArrayList<CubicCurve2D>();
        CubicCurve2D bezierCurve;
        int i;

        // now separate out the points. we assume that there are at least 4
        // points,
        // of which the first and last are dummy points (so there are only 2
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.