Class PACurveUtility
A class to maintain static versions of point reduction and curve-modeling methods. Called by PACurveMaker and other curve-modeling applications. Includes an implementation of the Ramer-Douglas-Peucker (RDP) point reduction algorithm, Bezier curve generation methods, and a simple brush stroke modeling method.
Drawing methods are supplied to simplify drawing calls for the objects generated by PACurveUtility and PACurveMaker. The curve and shape drawing methods in particular can be handled by the PABezShape class, which has its own fill and stroke properties for curves (Bezier paths with no fill) and shapes (Bezier paths that may be filled), which are not distinguished within PABezShape. When stroke, fill, and weight are supplied in method arguments for PABezShape instances, the methods will call PABezShape's drawQuick() methods, which use the current drawing context to determine fill, stroke, and weight properties.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PABezShapecalculateCurve(ArrayList<processing.core.PVector> framePoints) Creates a Bezier curve from a supplied set of points.static PABezShapecalculateWeightedCurve(ArrayList<processing.core.PVector> framePoints, float bias) static voidcalculateWeightedCurve(PABezShape bezPoints) Scales the position of the curve control points on a Bezier curve by a factor determined by the length of the line between the two anchor points and a bias value, such as PACurveUtility.LAMBDA (the default, in this method).static PABezShapecalculateWeightedCurve(PABezShape bezPoints, float bias) Scales the position of the curve control points on a Bezier curve by a factor determined by the length of the line between the two anchor points and a bias value, such as PACurveUtility.LAMBDA.(package private) static voidcomputeControlPoints(float[] K, float[] p1, float[] p2) static voidcurveDraw(processing.core.PApplet parent, PABezShape curve) Draws a Bezier path in a PApplet using 2D curve data and the local stroke color and weight of a PABezShape.static voidcurveDraw(processing.core.PApplet parent, PABezShape curve, int curveColor, float curveWeight) Draws a Bezier path in a PApplet using 2D curve data and supplied stroke color and weight.static voidcurveDraw(processing.core.PGraphics pg, PABezShape curve) Draws a Bezier path in a PGraphics using 2D curve data and local stroke color and weight of a PABezShape.static voidcurveDraw(processing.core.PGraphics pg, PABezShape curve, int curveColor, float curveWeight) Draws a Bezier path in a PGraphics using 2D curve data and supplied stroke color and weight.(package private) static intfindFurthest(ArrayList<processing.core.PVector> points, int a, int b, float epsilon) static voidindexedRDP(int startIndex, int endIndex, ArrayList<processing.core.PVector> allPoints, ArrayList<processing.core.PVector> rdpPoints, ArrayList<Integer> rdpIndices, float epsilon) Ramer-Douglas-Peucker point reduction algorithm (RDP), reduces points in allPoints and returns the result in rdpPoints.(package private) static floatlineDist(processing.core.PVector c, processing.core.PVector a, processing.core.PVector b) static voidlineDraw(processing.core.PApplet parent, ArrayList<processing.core.PVector> points, int lineColor, float lineWeight) Draws a line in a PApplet context using the PVector data in points and supplied color and weight.static voidlineDraw(processing.core.PGraphics pg, ArrayList<processing.core.PVector> points, int lineColor, float lineWeight) Draws a line in a PGraphics using the 2D PVector data and supplied color and weight.static processing.core.PVectornormalAtPoint(processing.core.PVector a1, processing.core.PVector a2, float u, float d) Calculates a normal to a line at a point on the line at parametric distance u, normalized if d = 1.static PABezShapequickBrushShape(ArrayList<processing.core.PVector> points, float brushWidth) static PABezShapequickBrushShape(ArrayList<processing.core.PVector> points, float brushWidth, boolean isDrawWeighted, float bias) Simulates a brush stroke as a PABezShape object by creating two Bezier curves offset on either side of a supplied list of 2D PVector objects and joining them into a closed shape with pointed ends.static PABezShapequickBrushShape(ArrayList<processing.core.PVector> points, float brushWidth, float bias) static voidrdp(int startIndex, int endIndex, ArrayList<processing.core.PVector> allPoints, ArrayList<processing.core.PVector> rdpPoints, float epsilon) Ramer-Douglas-Peucker point reduction algorithm (RDP), reduces points in allPoints and returns the result in rdpPoints.static voidreverseArray(ArrayList<processing.core.PVector> arr, int l, int r) Reverses the order of a portion of an ArrayList of PVector objects, between indices l and r, inclusive.(package private) static processing.core.PVectorscalarProjection(processing.core.PVector p, processing.core.PVector a, processing.core.PVector b) static processing.core.PVectorscaledNormalAtPoint(processing.core.PVector anchor, processing.core.PVector normal, float d) static voidshapeDraw(processing.core.PApplet parent, PABezShape shape) Draws a PABezShape in a PApplet using local fill, stroke, and weight of the shape.static voidshapeDraw(processing.core.PApplet parent, PABezShape shape, int shapeFill, int shapeStroke, float shapeWeight) Draws a PABezShape in a PApplet using supplied fill, stroke, and weight.static voidshapeDraw(processing.core.PGraphics pg, PABezShape shape) Draws a PABezShape in a PGraphics using local fill, stroke, and weight of the shape.static voidshapeDraw(processing.core.PGraphics pg, PABezShape shape, int shapeFill, int shapeStroke, float shapeWeight) Draws a PABezShape in a PGraphics using supplied fill, stroke, and weight.static processing.core.PVectorweightedControlVec(float ax, float ay, float cx, float cy, float w, float d)
-
Constructor Details
-
PACurveUtility
public PACurveUtility()
-
-
Method Details
-
rdp
public static void rdp(int startIndex, int endIndex, ArrayList<processing.core.PVector> allPoints, ArrayList<processing.core.PVector> rdpPoints, float epsilon) Ramer-Douglas-Peucker point reduction algorithm (RDP), reduces points in allPoints and returns the result in rdpPoints.- Parameters:
startIndex- start index in allPoints (usually 0 to begin with)endIndex- end index in allPoints (usually allPoints.size()-1 to begin with)allPoints- ArrayList of dense points, for example a hand-drawn linerdpPoints- an empty ArrayList for accumulating reduced pointsepsilon- the expected distance between reduced points
-
indexedRDP
public static void indexedRDP(int startIndex, int endIndex, ArrayList<processing.core.PVector> allPoints, ArrayList<processing.core.PVector> rdpPoints, ArrayList<Integer> rdpIndices, float epsilon) Ramer-Douglas-Peucker point reduction algorithm (RDP), reduces points in allPoints and returns the result in rdpPoints.- Parameters:
startIndex- start index in allPoints (usually 0 to begin with)endIndex- end index in allPoints (usually allPoints.size()-1 to begin with)allPoints- ArrayList of dense points, for example a hand-drawn linerdpPoints- an empty ArrayList for accumulating reduced pointsepsilon- the expected distance between reduced points
-
findFurthest
-
lineDist
static float lineDist(processing.core.PVector c, processing.core.PVector a, processing.core.PVector b) -
scalarProjection
static processing.core.PVector scalarProjection(processing.core.PVector p, processing.core.PVector a, processing.core.PVector b) -
calculateCurve
Creates a Bezier curve from a supplied set of points.- Parameters:
framePoints- An array of 2D PVector objects representing the points a Bezier curve will traverse- Returns:
- A Bezier curve path constructed of PABezShape objects
-
computeControlPoints
static void computeControlPoints(float[] K, float[] p1, float[] p2) -
calculateWeightedCurve
Scales the position of the curve control points on a Bezier curve by a factor determined by the length of the line between the two anchor points and a bias value, such as PACurveUtility.LAMBDA. It's most useful when a short control line segment follows a long segment.- Parameters:
weightedCurveShape-bias-
-
calculateWeightedCurve
public static PABezShape calculateWeightedCurve(ArrayList<processing.core.PVector> framePoints, float bias) -
calculateWeightedCurve
Scales the position of the curve control points on a Bezier curve by a factor determined by the length of the line between the two anchor points and a bias value, such as PACurveUtility.LAMBDA (the default, in this method). It's most useful when a short control line segment follows a long segment.- Parameters:
bezPoints- a Bezier path encapsulated in a PABezShape instance
-
weightedControlVec
public static processing.core.PVector weightedControlVec(float ax, float ay, float cx, float cy, float w, float d) -
quickBrushShape
public static PABezShape quickBrushShape(ArrayList<processing.core.PVector> points, float brushWidth, boolean isDrawWeighted, float bias) Simulates a brush stroke as a PABezShape object by creating two Bezier curves offset on either side of a supplied list of 2D PVector objects and joining them into a closed shape with pointed ends.- Parameters:
points- an ArrayList of 2D PVector objectsbrushWidth- width of the brush in pixelsisDrawWeighted- create a weighted version of the PABezShape shapebias- adjusts distances between control points and anchor points- Returns:
-
quickBrushShape
public static PABezShape quickBrushShape(ArrayList<processing.core.PVector> points, float brushWidth) -
quickBrushShape
public static PABezShape quickBrushShape(ArrayList<processing.core.PVector> points, float brushWidth, float bias) -
normalAtPoint
public static processing.core.PVector normalAtPoint(processing.core.PVector a1, processing.core.PVector a2, float u, float d) Calculates a normal to a line at a point on the line at parametric distance u, normalized if d = 1.- Parameters:
a1- 2D PVector, first pointa2- 2D PVector, second pointu- parametric distance along the line from a1 to a2d- distance of the normal from the line a1, a2- Returns:
- Normal to line through a1 and a2
-
scaledNormalAtPoint
public static processing.core.PVector scaledNormalAtPoint(processing.core.PVector anchor, processing.core.PVector normal, float d) - Parameters:
anchor- 2D PVector, the point from which the normal extendsnormal- 2D PVector, normal to anchord- distance for scaling the normal, distance from anchor to returned PVector- Returns:
- 2D PVector, the normal scaled by d
-
reverseArray
Reverses the order of a portion of an ArrayList of PVector objects, between indices l and r, inclusive.- Parameters:
arr- an ArrayList of PVector objectsl- index at which to start reversing order of elementsr- index at which to stop reversing order of elements
-
lineDraw
public static void lineDraw(processing.core.PApplet parent, ArrayList<processing.core.PVector> points, int lineColor, float lineWeight) Draws a line in a PApplet context using the PVector data in points and supplied color and weight.- Parameters:
parent- a PApplet where drawing takes place on screenpoints- ArrayList of 2D PVector objects, typically a point set without successive identical pointslineColor- color for the line that is drawnlineWeight- weight for the line that is drawn
-
lineDraw
public static void lineDraw(processing.core.PGraphics pg, ArrayList<processing.core.PVector> points, int lineColor, float lineWeight) Draws a line in a PGraphics using the 2D PVector data and supplied color and weight.- Parameters:
pg- a PGraphics where drawing takes place off screenpoints- ArrayList of 2D PVector objects, typically a point set without successive identical pointslineColor- color for the line that is drawnlineWeight- weight for the line that is drawn
-
curveDraw
public static void curveDraw(processing.core.PApplet parent, PABezShape curve, int curveColor, float curveWeight) Draws a Bezier path in a PApplet using 2D curve data and supplied stroke color and weight. The path is drawn with no fill.- Parameters:
parent-curve-curveColor-curveWeight-
-
curveDraw
Draws a Bezier path in a PApplet using 2D curve data and the local stroke color and weight of a PABezShape. If the PABezShape is filled, the fill will be drawn.- Parameters:
parent-curve-
-
curveDraw
public static void curveDraw(processing.core.PGraphics pg, PABezShape curve, int curveColor, float curveWeight) Draws a Bezier path in a PGraphics using 2D curve data and supplied stroke color and weight. The path is drawn with no fill.- Parameters:
pg-curve-curveColor-curveWeight-
-
curveDraw
Draws a Bezier path in a PGraphics using 2D curve data and local stroke color and weight of a PABezShape. If the PABezShape is filled, the fill will be drawn.- Parameters:
pg-curve-
-
shapeDraw
public static void shapeDraw(processing.core.PApplet parent, PABezShape shape, int shapeFill, int shapeStroke, float shapeWeight) Draws a PABezShape in a PApplet using supplied fill, stroke, and weight. If weight == 0, the shape is drawn with no stroke.- Parameters:
parent-shape-shapeFill-shapeStroke-shapeWeight-
-
shapeDraw
Draws a PABezShape in a PApplet using local fill, stroke, and weight of the shape.- Parameters:
parent-shape-
-
shapeDraw
public static void shapeDraw(processing.core.PGraphics pg, PABezShape shape, int shapeFill, int shapeStroke, float shapeWeight) Draws a PABezShape in a PGraphics using supplied fill, stroke, and weight. If weight == 0, the shape is drawn with no stroke.- Parameters:
pg-shape-shapeFill-shapeStroke-shapeWeight-
-
shapeDraw
Draws a PABezShape in a PGraphics using local fill, stroke, and weight of the shape.- Parameters:
pg-shape-
-