bezier_tangent()#

Calculates the tangent of a point on a Bezier curve.

Examples#

example picture for bezier_tangent()
 1def setup():
 2    py5.no_fill()
 3    py5.bezier(85, 20, 10, 10, 90, 90, 15, 80)
 4    steps = 6
 5    py5.fill(255)
 6    for i in range(0, steps+1):
 7        t = i / steps
 8        # get the location of the point
 9        x = py5.bezier_point(85, 10, 90, 15, t)
10        y = py5.bezier_point(20, 10, 90, 80, t)
11        # get the tangent points
12        tx = py5.bezier_tangent(85, 10, 90, 15, t)
13        ty = py5.bezier_tangent(20, 10, 90, 80, t)
14        # calculate an angle from_ the tangent points
15        a = py5.atan2(ty, tx)
16        a += py5.PI
17        py5.stroke(255, 102, 0)
18        py5.line(x, y, py5.cos(a)*30+x, py5.sin(a)*30+y)
19        # the following line of code makes a line
20        # inverse of the above line
21        #line(x, y, cos(a)*-30+x, sin(a)*-30+y)
22        py5.stroke(0)
23        py5.ellipse(x, y, 5, 5)
example picture for bezier_tangent()
 1def setup():
 2    py5.no_fill()
 3    py5.bezier(85, 20, 10, 10, 90, 90, 15, 80)
 4    py5.stroke(255, 102, 0)
 5    steps = 16
 6    for i in range(0, steps+1):
 7        t = i / steps
 8        x = py5.bezier_point(85, 10, 90, 15, t)
 9        y = py5.bezier_point(20, 10, 90, 80, t)
10        tx = py5.bezier_tangent(85, 10, 90, 15, t)
11        ty = py5.bezier_tangent(20, 10, 90, 80, t)
12        a = py5.atan2(ty, tx)
13        a -= py5.HALF_PI
14        py5.line(x, y, py5.cos(a)*8+x, py5.sin(a)*8+y)

Description#

Calculates the tangent of a point on a Bezier curve. There is a good definition of tangent on Wikipedia.

Underlying Processing method: bezierTangent

Syntax#

bezier_tangent(a: float, b: float, c: float, d: float, t: float, /) -> float

Parameters#

  • a: float - coordinate of first point on the curve

  • b: float - coordinate of first control point

  • c: float - coordinate of second control point

  • d: float - coordinate of second point on the curve

  • t: float - value between 0 and 1

Updated on November 12, 2021 11:30:58am UTC