Name

curveTangent()

Description

Calculates the tangent of a point on a curve. There's a good definition of tangent on Wikipedia.

Examples

  • size(400, 400);
    noFill();
    curve(20, 104, 292, 96, 292, 244, 60, 260); 
    int steps = 6;
    for (int i = 0; i <= steps; i++) {
      float t = i / float(steps);
      float x = curvePoint(20, 292, 292, 60, t);
      float y = curvePoint(104, 96, 244, 260, t);
      //ellipse(x, y, 20, 20);
      float tx = curveTangent(20, 292, 292, 60, t);
      float ty = curveTangent(104, 96, 244, 260, t);
      float a = atan2(ty, tx);
      a -= PI/2.0;
      line(x, y, cos(a)*32 + x, sin(a)*32 + y);
    }
    Image output for example 1

Syntax

  • curveTangent(a, b, c, d, t)

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

Return

  • float