Skip to content

# `typerig.core.objects.cubicbezier`

## typerig.core.objects.cubicbezier (version 0.26.6)

    # MODULE: TypeRig / Core / Cubic Bezier (Object)
    # -----------------------------------------------------------
    # (C) Vassil Kateliev, 2016-2020        (http://www.kateliev.com)
    # (C) Karandash Type Foundry            (http://www.karandash.eu)
    #------------------------------------------------------------
    # www.typerig.com

### Modules

- math

### Classes

- builtin.object
- - CubicBezier

## class CubicBezier(builtin.object)

      # - Classes -----------------------------

#### Methods

init(self, *argv)

repr(self)

asList(self)

      # -- Modifiers

doSwap(self)

doTransform(self, transform=None)

get_handle_length(self)

      Returns handle length and radii from base points.

lerp_first(self, shift)

lerp_last(self, shift)

solve_curvature(self, time)

      Find Curvature of on-curve point at given time

solve_derivative(self, time)

      Returns point of on-curve point at given time and vector of 1st and 2nd derivative.

solve_distance_end(self, distance, timeStep=0.01)

      Returns time at which the given distance to end of bezier is met.
      Probing is executed withing timeStep in range from 0 to 1. The finer the step the preciser the results.

solve_distance_start(self, distance, timeStep=0.01)

      Returns time at which the given distance to beginning of bezier is met.
      Probing is executed withing timeStep in range from 0 to 1. The finer the step the preciser the results.

solve_extremes(self)

      Finds curve extremes and returns [(extreme_01_x, extreme_01_y, extreme_01_t)...(extreme_n_x, extreme_n_y, extreme_n_t)]

solve_handle_distance_from_base(self, ratio=(0.5, 0.5))

      Finds new handle positions for given ratio from base points.

solve_hobby(self, curvature=(0.9, 0.9))

      Calculates and applies John Hobby's mock-curvature-smoothness by given curvature - tuple(float,float) or (float)
      Based on Metapolator's Hobby Spline by Juraj Sukop, Lasse Fister, Simon Egli

solve_hobby_curvature(self)

      Returns current curvature coefficients (complex(alpha), complex(beta)) for
      both handles according to John Hobby's mock-curvature calculation

solve_parallel(self, vector, fullOutput=False)

      Finds the t value along a cubic Bezier where a tangent (1st derivative) is parallel with the direction vector.
      vector: a pair of values representing the direction of interest (magnitude is ignored).
      returns 0.0 <= t <= 1.0 or None

      # Solving the dot product of cubic beziers first derivate to the vector given B'(t) x V. Two vectors are perpendicular if their dot product is zero.
      # So if you could find the (1) perpendicular of V it will be collinear == tangent of the curve so the equation to be solved is:
      # B'(t) x V(x,y) = 0; -(a*t^2 + b*t + c)*x + (g*t^2 + h*t + i)*y = 0 solved for t, where a,b,c are coefs for X and g,h,i for Y B'(t) derivate of curve
      #
      # Inspired by answer given by 'unutbu' on the stackoverflow question: http://stackoverflow.com/questions/20825173/how-to-find-a-point-if-any-on-quadratic-bezier-with-a-given-tangent-direction
      # Recoded and recalculated for qubic beziers. Used 'Rearrange It' app at http://www.wolframalpha.com/widgets/view.jsp?id=4be4308d0f9d17d1da68eea39de9b2ce was invaluable.
      #
      # DOTO: Fix calculation optimization error - will yield false positive result in cases #1 and #2 if vector is 45 degrees

solve_point(self, time)

      Find point on cubic bezier at given time

solve_proportional_handles(self, proportion=0.3)

      Equalizes handle length to given float(proportion)

solve_slice(self, time)

      Returns two segments representing cubic bezier sliced at given time.
      Output: list [(Start), (Start_BCP_out), (Slice_BCP_in), (Slice), (Slice_BCP_out), (End_BCP_in), (End)] of tuples (x,y)

solve_tunni(self)

      Make proportional handles keeping curvature and on-curve point positions
      Based on modified Andres Torresi implementation of Eduardo Tunni's method for control points

#### Descriptors

dict

      dictionary for instance variables (if defined)

weakref

      list of weak references to the object (if defined)

height

line

points

tuple

width

x

x_max

y

y_max

## `CubicBezier`

## typerig.core.objects.cubicbezier.CubicBezier = class CubicBezier(__builtin__.object)

      # - Classes -----------------------------

#### Methods

__init__(self, *argv)

__repr__(self)

asList(self)

      # -- Modifiers

doSwap(self)

doTransform(self, transform=None)

get_handle_length(self)

      Returns handle length and radii from base points.

lerp_first(self, shift)

lerp_last(self, shift)

solve_curvature(self, time)

      Find Curvature of on-curve point at given time

solve_derivative(self, time)

      Returns point of on-curve point at given time and vector of 1st and 2nd derivative.

solve_distance_end(self, distance, timeStep=0.01)

      Returns time at which the given distance to end of bezier is met.
      Probing is executed withing timeStep in range from 0 to 1. The finer the step the preciser the results.

solve_distance_start(self, distance, timeStep=0.01)

      Returns time at which the given distance to beginning of bezier is met.
      Probing is executed withing timeStep in range from 0 to 1. The finer the step the preciser the results.

solve_extremes(self)

      Finds curve extremes and returns [(extreme_01_x, extreme_01_y, extreme_01_t)...(extreme_n_x, extreme_n_y, extreme_n_t)]

solve_handle_distance_from_base(self, ratio=(0.5, 0.5))

      Finds new handle positions for given ratio from base points.

solve_hobby(self, curvature=(0.9, 0.9))

      Calculates and applies John Hobby's mock-curvature-smoothness by given curvature - tuple(float,float) or (float)
      Based on Metapolator's Hobby Spline by Juraj Sukop, Lasse Fister, Simon Egli

solve_hobby_curvature(self)

      Returns current curvature coefficients (complex(alpha), complex(beta)) for
      both handles according to John Hobby's mock-curvature calculation

solve_parallel(self, vector, fullOutput=False)

      Finds the t value along a cubic Bezier where a tangent (1st derivative) is parallel with the direction vector.
      vector: a pair of values representing the direction of interest (magnitude is ignored).
      returns 0.0 <= t <= 1.0 or None

      # Solving the dot product of cubic beziers first derivate to the vector given B'(t) x V. Two vectors are perpendicular if their dot product is zero.
      # So if you could find the (1) perpendicular of V it will be collinear == tangent of the curve so the equation to be solved is:
      # B'(t) x V(x,y) = 0; -(a*t^2 + b*t + c)*x + (g*t^2 + h*t + i)*y = 0 solved for t, where a,b,c are coefs for X and g,h,i for Y B'(t) derivate of curve
      #
      # Inspired by answer given by 'unutbu' on the stackoverflow question: http://stackoverflow.com/questions/20825173/how-to-find-a-point-if-any-on-quadratic-bezier-with-a-given-tangent-direction
      # Recoded and recalculated for qubic beziers. Used 'Rearrange It' app at http://www.wolframalpha.com/widgets/view.jsp?id=4be4308d0f9d17d1da68eea39de9b2ce was invaluable.
      #
      # DOTO: Fix calculation optimization error - will yield false positive result in cases #1 and #2 if vector is 45 degrees

solve_point(self, time)

      Find point on cubic bezier at given time

solve_proportional_handles(self, proportion=0.3)

      Equalizes handle length to given float(proportion)

solve_slice(self, time)

      Returns two segments representing cubic bezier sliced at given time.
      Output: list [(Start), (Start_BCP_out), (Slice_BCP_in), (Slice), (Slice_BCP_out), (End_BCP_in), (End)] of tuples (x,y)

solve_tunni(self)

      Make proportional handles keeping curvature and on-curve point positions
      Based on modified Andres Torresi implementation of Eduardo Tunni's method for control points

#### Descriptors

__dict__

      dictionary for instance variables (if defined)

__weakref__

      list of weak references to the object (if defined)

height

line

points

tuple

width

x

x_max

y

y_max

### `solve_point`

typerig.core.objects.cubicbezier.CubicBezier.solve_point = solve_point(self, time) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Find point on cubic bezier at given time

### `solve_derivative`

typerig.core.objects.cubicbezier.CubicBezier.solve_derivative = solve_derivative(self, time) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Returns point of on-curve point at given time and vector of 1st and 2nd derivative.

### `solve_curvature`

typerig.core.objects.cubicbezier.CubicBezier.solve_curvature = solve_curvature(self, time) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Find Curvature of on-curve point at given time

### `solve_slice`

typerig.core.objects.cubicbezier.CubicBezier.solve_slice = solve_slice(self, time) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Returns two segments representing cubic bezier sliced at given time.
      Output: list [(Start), (Start_BCP_out), (Slice_BCP_in), (Slice), (Slice_BCP_out), (End_BCP_in), (End)] of tuples (x,y)

### `solve_distance_start`

typerig.core.objects.cubicbezier.CubicBezier.solve_distance_start = solve_distance_start(self, distance, timeStep=0.01) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Returns time at which the given distance to beginning of bezier is met.
      Probing is executed withing timeStep in range from 0 to 1. The finer the step the preciser the results.

### `solve_distance_end`

typerig.core.objects.cubicbezier.CubicBezier.solve_distance_end = solve_distance_end(self, distance, timeStep=0.01) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Returns time at which the given distance to end of bezier is met.
      Probing is executed withing timeStep in range from 0 to 1. The finer the step the preciser the results.

### `solve_extremes`

typerig.core.objects.cubicbezier.CubicBezier.solve_extremes = solve_extremes(self) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Finds curve extremes and returns [(extreme_01_x, extreme_01_y, extreme_01_t)...(extreme_n_x, extreme_n_y, extreme_n_t)]

### `solve_parallel`

typerig.core.objects.cubicbezier.CubicBezier.solve_parallel = solve_parallel(self, vector, fullOutput=False) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Finds the t value along a cubic Bezier where a tangent (1st derivative) is parallel with the direction vector.
      vector: a pair of values representing the direction of interest (magnitude is ignored).
      returns 0.0 <= t <= 1.0 or None

      # Solving the dot product of cubic beziers first derivate to the vector given B'(t) x V. Two vectors are perpendicular if their dot product is zero.
      # So if you could find the (1) perpendicular of V it will be collinear == tangent of the curve so the equation to be solved is:
      # B'(t) x V(x,y) = 0; -(a*t^2 + b*t + c)*x + (g*t^2 + h*t + i)*y = 0 solved for t, where a,b,c are coefs for X and g,h,i for Y B'(t) derivate of curve
      #
      # Inspired by answer given by 'unutbu' on the stackoverflow question: http://stackoverflow.com/questions/20825173/how-to-find-a-point-if-any-on-quadratic-bezier-with-a-given-tangent-direction
      # Recoded and recalculated for qubic beziers. Used 'Rearrange It' app at http://www.wolframalpha.com/widgets/view.jsp?id=4be4308d0f9d17d1da68eea39de9b2ce was invaluable.
      #
      # DOTO: Fix calculation optimization error - will yield false positive result in cases #1 and #2 if vector is 45 degrees

### `solve_proportional_handles`

typerig.core.objects.cubicbezier.CubicBezier.solve_proportional_handles = solve_proportional_handles(self, proportion=0.3) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Equalizes handle length to given float(proportion)

### `solve_handle_distance_from_base`

typerig.core.objects.cubicbezier.CubicBezier.solve_handle_distance_from_base = solve_handle_distance_from_base(self, ratio=(0.5, 0.5)) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Finds new handle positions for given ratio from base points.

### `get_handle_length`

typerig.core.objects.cubicbezier.CubicBezier.get_handle_length = get_handle_length(self) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Returns handle length and radii from base points.

### `solve_hobby`

typerig.core.objects.cubicbezier.CubicBezier.solve_hobby = solve_hobby(self, curvature=(0.9, 0.9)) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Calculates and applies John Hobby's mock-curvature-smoothness by given curvature - tuple(float,float) or (float)
      Based on Metapolator's Hobby Spline by Juraj Sukop, Lasse Fister, Simon Egli

### `solve_hobby_curvature`

typerig.core.objects.cubicbezier.CubicBezier.solve_hobby_curvature = solve_hobby_curvature(self) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Returns current curvature coefficients (complex(alpha), complex(beta)) for
      both handles according to John Hobby's mock-curvature calculation

### `solve_tunni`

typerig.core.objects.cubicbezier.CubicBezier.solve_tunni = solve_tunni(self) unbound typerig.core.objects.cubicbezier.CubicBezier method

      Make proportional handles keeping curvature and on-curve point positions
      Based on modified Andres Torresi implementation of Eduardo Tunni's method for control points