keyframeReduction.classes.fit module

class keyframeReduction.classes.fit.FitBezier(points, error=2.5, weightedTangents=True)

Bases: object

Ported from Paper.js - The Swiss Army Knife of Vector Graphics Scripting. http://paperjs.org/

addCurve(pt1, tan1, tan2, pt2)
Parameters:
  • pt1 (Vector2D) –
  • tan1 (Vector2D) –
  • tan2 (Vector2D) –
  • pt2 (Vector2D) –
chordLengthParameterize(first, last)

Assign parameter values to digitized points using relative distances between points.

Parameters:
  • first (int) –
  • last (int) –
Returns:

Chord length parameterization

Return type:

dict

error
Returns:Maximum error
Return type:int/float
evaluate(degree, curve, t)

Evaluate a bezier curve at a particular parameter value.

Parameters:
  • degree (int) –
  • curve (list) –
  • t (float) –
Returns:

Point on curve

Return type:

Vector2D

findMaxError(first, last, curve, u)

Find the maximum squared distance of digitized points to fitted curve.

Parameters:
  • first (int) –
  • last (int) –
  • curve (list) –
  • u (dict) –
Returns:

Max distance and max index

Return type:

tuple

findRoot(curve, point, u)

Use Newton-Raphson iteration to find better root.

Parameters:
  • curve (list) –
  • point (Vector2D) –
  • u (Vector2D) –
Returns:

New root point

Return type:

Vector2D

fit()

Fit bezier curves to the points based on the provided maximum error value and the bezier weighted tangents.

Returns:Keyframes
Return type:list
fitCubic(first, last, tan1, tan2)

But a cubic bezier points between the provided first and last index and it’s tangents. Based in the weighted tangent settings the iterations will be adjusted to gain speed. If a curve can be matched the curve will be added to the keyframes, if not the curve will be split at the point of max error and the function will be called again.

Parameters:
  • first (int) –
  • last (int) –
  • tan1 (Vector2D) –
  • tan2 (Vector2D) –
generateBezier(first, last, uPrime, tan1, tan2)

Based on the weighted tangent setting either use a least-squares method to find Bezier controls points for a region or use Wu/Barsky heuristic.

Parameters:
  • first (int) –
  • last (int) –
  • uPrime (dict) –
  • tan1 (Vector2D) –
  • tan2 (Vector2D) –
keyframes
Returns:Keyframes
Return type:list
points
Returns:Vector2Ds
Return type:list
reparameterize(first, last, u, curve)

Given set of points and their parameterization, try to find a better parameterization.

Parameters:
  • first (int) –
  • last (int) –
  • u (dict) –
  • curve (list) –
weightedTangents
Returns:Weighted tangents
Return type:bool