Class CardinalSplines

java.lang.Object
org.jhotdraw8.geom.CardinalSplines

public class CardinalSplines extends Object
Provides conversion functions from cardinal splines (c-splines) to bezier curves.
  • Method Details

    • cardinalSplineToBezier

      public static javafx.geometry.Point2D[] cardinalSplineToBezier(javafx.geometry.Point2D[] p, double c)
      Converts a cardinal spline into a bezier curve.

      Cardinal spline from B to E with control points A, B, E, F and tension parameter c:

             B         F
           /   \     /
         /      \   /
       A          E
       
      The tangent vectors of the cardinal spline are:
      • Tb = c * (E - A)
      • Te = c * (F - B)

      Cubic bezier curve from B to E with control points B, C, D, E.

             B----C   F
           /   \     /
         /      \   /
       A     D----E
       
      The tangent vectors of the cubic bezier curve are:
      • Tb = 3 * (C - B)
      • Te = 3 * (E - D)
      Therefore, we can compute C and D from the cardinal spline as follows:
      • C = B + (E - A) * c / 3
      • D = E - (F - B) * c/ 3
      References:
      Stackoverflow. Converting a Cubic Bezier Curves into a Cardinal Spline and back. Copyright MBo. CC BY-SA 4.0 license.
      stackoverflow.com
      Parameters:
      p - the points of the cardinal spline
      c - the tension of the cardinal spline
      Returns:
      the cubic bezier curves (first point is moveTo, subsequent triples of points are curveTos.
    • cardinalSplineToBezier

      public static javafx.geometry.Point2D[] cardinalSplineToBezier(double[] p, double c)
    • cardinalSplineToBezier

      public static javafx.geometry.Point2D[] cardinalSplineToBezier(List<Double> p, double c)