java.lang.Object
org.jhotdraw8.geom.CubicCurves
Provides utility methods for Bézier curves.
- Author:
- Werner Randelshofer
-
Method Summary
Modifier and TypeMethodDescriptionstatic doubleComputes the arc length s.static doubleComputes the arc length s from time 0 to time t using an integration method.static @NonNull PointAndDerivativeeval(double[] a, int offsetA, double t) Evaluates the given curve at the specified time.static @NonNull PointAndDerivativeeval(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double t) Evaluates the given curve at the specified time.static ToDoubleFunction<Double> getArcLengthIntegrand(double[] v, int offset) From paper.js, src/path/Curve.js, MIT License.static doubleinvArcLength(double @NonNull [] p, int offset, double s, double epsilon) Computes time t at the given arc length s.static doubleinvArcLength(double @NonNull [] p, int offset, double s, double totalArcLength, double epsilon) Computes time t at the given arc length s.static double @Nullable []merge(double[] a, int offsetA, double[] b, int offsetB, double tolerance) Tries to merge two bézier curves.static double @Nullable []merge(double x0, double y0, double x01, double y01, double x012, double y012, double x0123, double y0123, double x123, double y123, double x23, double y23, double x3, double y3, double tolerance) Tries to merge two bézier curves.static voidsplit(double[] p, int o, double t, double[] f, int fo, double[] s, int so) static voidsplit(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double t, double[] left, double[] right) Splits the provided bezier curve into two parts.static voidsplit(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double t, @Nullable DoubleConsumer8 first, @Nullable DoubleConsumer8 second) Splits the provided bezier curve into two parts at the specified parameter valuet.split(CubicCurve2D.Double source, double t) Splits the provided bezier curve into two parts at the specified parameter valuet.static voidsplit(CubicCurve2D.Double source, double t, CubicCurve2D.Double left, CubicCurve2D.Double right) Splits the provided bezier curve into two parts at the specified parameter valuet.static voidsplitCubicCurveTo(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double t, @Nullable DoubleConsumer6 left, @Nullable DoubleConsumer6 right) Splits the provided bezier curve into two parts at the specified parameter valuet.static voidsubCurve(double @NonNull [] q, int qOffset, double ta, double tb, double @NonNull [] segment, int segmentOffset) Extracts the specified segment [ta,tb] from the given cubic curve.static double[]
-
Method Details
-
eval
Evaluates the given curve at the specified time.- Parameters:
a- points of the curveoffsetA- index of the first point in arrayat- the time- Returns:
- the point at time t
-
eval
public static @NonNull PointAndDerivative eval(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double t) Evaluates the given curve at the specified time.- Parameters:
x0- point P0 of the curvey0- point P0 of the curvex1- point P1 of the curvey1- point P1 of the curvex2- point P2 of the curvey2- point P2 of the curvex3- point P3 of the curvey3- point P3 of the curvet- the time- Returns:
- the point at time t
-
merge
public static double @Nullable [] merge(double[] a, int offsetA, double[] b, int offsetB, double tolerance) Tries to merge two bézier curves. Returns the new control point.- Parameters:
tolerance- distance (radius) at which the joined point may be off from x0123,y0123.- Returns:
- the control points of the new curve (x0,y0)(x1,y1)(x2,y2)(x3,y3), null if merging failed
-
merge
public static double @Nullable [] merge(double x0, double y0, double x01, double y01, double x012, double y012, double x0123, double y0123, double x123, double y123, double x23, double y23, double x3, double y3, double tolerance) Tries to merge two bézier curves. Returns the new control point.- Parameters:
x0- point P0 of the first curvey0- point P0 of the first curvex01- point P1 of the first curvey01- point P1 of the first curvex012- point P2 of the first curvey012- point P2 of the first curvex0123- point P3 of the first curve or point p0 of the second curve respectivelyy0123- point P3 of the first curve or point p0 of the second curve respectivelyx123- point P1 of the second curvey123- point P1 of the second curvex23- point P2 of the second curvey23- point P2 of the second curvex3- point P3 of the second curvey3- point P3 of the second curvetolerance- distance (radius) at which the joined point may be off from x0123,y0123.- Returns:
- the control points of the new curve (x0,y0)(x1,y1)(x2,y2)(x3,y3), null if merging failed
-
split
public static SimpleOrderedPair<CubicCurve2D.Double,CubicCurve2D.Double> split(CubicCurve2D.Double source, double t) Splits the provided bezier curve into two parts at the specified parameter valuet.Reference:
- Stackoverflow, Splitting a bezier curve, Copyright Jonathan, CC BY-SA 4.0 license
- stackoverflow.com
-
split
public static void split(CubicCurve2D.Double source, double t, CubicCurve2D.Double left, CubicCurve2D.Double right) Splits the provided bezier curve into two parts at the specified parameter valuet.Reference:
- Stackoverflow, Splitting a bezier curve, Copyright Jonathan, CC BY-SA 4.0 license
- stackoverflow.com
-
splitCubicCurveTo
public static void splitCubicCurveTo(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double t, @Nullable DoubleConsumer6 left, @Nullable DoubleConsumer6 right) Splits the provided bezier curve into two parts at the specified parameter valuet.Reference:
- Stackoverflow, Splitting a bezier curve, Copyright Jonathan, CC BY-SA 4.0 license
- stackoverflow.com
- Parameters:
x0- point P0 of the curvey0- point P0 of the curvex1- point P1 of the curvey1- point P1 of the curvex2- point P2 of the curvey2- point P2 of the curvex3- point P3 of the curvey3- point P3 of the curvet- where to splitleft- if not null, accepts the curve from x1,y1 to tright- if not null, accepts the curve from t to x4,y4
-
split
public static void split(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double t, @Nullable DoubleConsumer8 first, @Nullable DoubleConsumer8 second) Splits the provided bezier curve into two parts at the specified parameter valuet.Reference:
- Stackoverflow, Splitting a bezier curve, Copyright Jonathan, CC BY-SA 4.0 license
- stackoverflow.com
- Parameters:
x0- point P0 of the curvey0- point P0 of the curvex1- point P1 of the curvey1- point P1 of the curvex2- point P2 of the curvey2- point P2 of the curvex3- point P3 of the curvey3- point P3 of the curvet- where to splitfirst- if not null, accepts the curve from x1,y1 to tsecond- if not null, accepts the curve from t to x4,y4
-
split
public static void split(double[] p, int o, double t, double[] f, int fo, double[] s, int so) -
split
public static void split(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double t, double[] left, double[] right) Splits the provided bezier curve into two parts.Reference:
- Stackoverflow, Splitting a bezier curve, Copyright Jonathan, CC BY-SA 4.0 license
- stackoverflow.com
- Parameters:
x0- point P0 of the curvey0- point P0 of the curvex1- point P1 of the curvey1- point P1 of the curvex2- point P2 of the curvey2- point P2 of the curvex3- point P3 of the curvey3- point P3 of the curvet- where to splitleft- if not null, accepts the curve from x1,y1 to tright- if not null, accepts the curve from t to x4,y4
-
subCurve
public static void subCurve(double @NonNull [] q, int qOffset, double ta, double tb, double @NonNull [] segment, int segmentOffset) Extracts the specified segment [ta,tb] from the given cubic curve.- Parameters:
q- the cubic bezier curveqOffset- the index of the first curve parameter in qta- where to split fromtb- where to split tosegment- the output arraysegmentOffset- the index of the first curve parameter in segment
-
getArcLengthIntegrand
From paper.js, src/path/Curve.js, MIT License.References:
- paper.js. Copyright (c) 2011 - 2020 Jürg Lehni & Jonathan Puckey. MIT License.
- github.com
- Parameters:
v- a cubic bezier curveoffset- offset into array v- Returns:
- the arc length integrand of a cubic Bézier curve
-
toArray
-
arcLength
Computes the arc length s.- Parameters:
p- points of the curveoffset- index of the first point in arraypepsilon-- Returns:
- the arc length
-
arcLength
Computes the arc length s from time 0 to time t using an integration method.- Parameters:
p- points of the curveoffset- index of the first point in arraypt- the timeepsilon- the error tolerance- Returns:
- the arc length
-
invArcLength
Computes time t at the given arc length s.- Parameters:
p- points of the curveoffset- index of the first point in arrayps- arc lengthepsilon-- Returns:
- t at s
-
invArcLength
public static double invArcLength(double @NonNull [] p, int offset, double s, double totalArcLength, double epsilon) Computes time t at the given arc length s.- Parameters:
p- points of the curveoffset- index of the first point in arrayps- arc lengthtotalArcLength- the total arc length of the curveepsilon-- Returns:
- t at s
-