示例#1
0
    private static Point2D evalParametric(CubicCurve2D curve, double t) {
      if (null == curve) {
        return null;
      }

      // B(t) = (1-t)^3 P_0 + 3(1-t)^2t C_1 + 3(1 - t)t^2 C_2 + t^3 P_1
      // do nothing fancy, just calculate it.
      double rx =
          ((Math.pow((1 - t), 3) * curve.getX1()))
              + (3 * Math.pow((1 - t), 2) * t * curve.getCtrlX1())
              + (3 * (1 - t) * t * t * curve.getCtrlX2())
              + (t * t * t * curve.getX2());
      double ry =
          ((Math.pow((1 - t), 3) * curve.getY1()))
              + (3 * Math.pow((1 - t), 2) * t * curve.getCtrlY1())
              + (3 * (1 - t) * t * t * curve.getCtrlY2())
              + (t * t * t * curve.getY2());

      return new Point2D.Float((float) rx, (float) ry);
    }
示例#2
0
    private static Point2D evalParametricTangent(CubicCurve2D curve, double t) {
      if (null == curve) {
        return null;
      }

      // B'(t) = 3(1-t)^2 P_0 + 3((1-t)^2 - 2t(1-t)) C_1
      //                      + 3(2t(1-t)-t^2) C_2
      //                      + 3t^2 P_1
      // Calculate the x and y values at t of the derivative of the cubic
      // Bezier.
      double rx =
          ((3 - (6 * t) + (3 * t * t)) * curve.getX1())
              + ((9 - (24 * t) + (15 * t * t)) * curve.getCtrlX1())
              + (((6 * t) - (9 * t * t)) * curve.getCtrlX2())
              + ((3 * t * t) * curve.getX2());
      double ry =
          ((3 - (6 * t) + (3 * t * t)) * curve.getY1())
              + ((9 - (24 * t) + (15 * t * t)) * curve.getCtrlY1())
              + (((6 * t) - (9 * t * t)) * curve.getCtrlY2())
              + ((3 * t * t) * curve.getY2());

      return new Point2D.Float((float) rx, (float) ry);
    }