Static p5_sys::global::bezierTangent [−][src]
pub static bezierTangent: BezierTangentInternalType
Expand description
Evaluates the tangent to the Bezier at position t for points a, b, c, d. The parameters a and d are the first and last points on the curve, and b and c are the control points. The final parameter t varies between 0 and 1.
Examples
noFill(); bezier(85, 20, 10, 10, 90, 90, 15, 80); let steps = 6; fill(255); for (let i = 0; i <= steps; i++) { let t = i / steps; // Get the location of the point let x = bezierPoint(85, 10, 90, 15, t); let y = bezierPoint(20, 10, 90, 80, t); // Get the tangent points let tx = bezierTangent(85, 10, 90, 15, t); let ty = bezierTangent(20, 10, 90, 80, t); // Calculate an angle from the tangent points let a = atan2(ty, tx); a += PI; stroke(255, 102, 0); line(x, y, cos(a) * 30 + x, sin(a) * 30 + y); // The following line of code makes a line // inverse of the above line //line(x, y, cos(a)*-30 + x, sin(a)*-30 + y); stroke(0); ellipse(x, y, 5, 5); }
noFill(); bezier(85, 20, 10, 10, 90, 90, 15, 80); stroke(255, 102, 0); let steps = 16; for (let i = 0; i <= steps; i++) { let t = i / steps; let x = bezierPoint(85, 10, 90, 15, t); let y = bezierPoint(20, 10, 90, 80, t); let tx = bezierTangent(85, 10, 90, 15, t); let ty = bezierTangent(20, 10, 90, 80, t); let a = atan2(ty, tx); a -= HALF_PI; line(x, y, cos(a) * 8 + x, sin(a) * 8 + y); }
Parameters
a
coordinate of first point on the curve
b
coordinate of first control point
c
coordinate of second control point
d
coordinate of second point on the curve
t
value between 0 and 1