Uzay

Tangent Line

Tangent line at a point on a parametric curve

What is a Tangent Line?

A tangentLine draws the tangent to a parametric curve at a given parameter value tt. It creates a point on the curve and a line segment aligned with the derivative direction. Useful for:

  • Visualizing the derivative of a curve
  • Showing instantaneous direction of motion
  • Combining with curvePoint for interactive tangent exploration

The tangent direction is computed numerically, so you don't need to provide a derivative function.

Basic Usage

import { tangentLine } from "uzay";

const f = (t: number) => vec3(Math.cos(t), Math.sin(t), t * 0.3);

scene.create("parametricfunction3d", {
  f,
  tStart: 0,
  tEnd: Math.PI * 4,
  samples: 200,
  color: "dodgerblue",
});

const tl = tangentLine(scene, {
  f,
  t: 1.0,
  color: "yellow",
  length: 2,
});

This draws a yellow tangent line of length 2 at t=1t = 1 on the helix, centered on the curve point.

Reactive Parameter

Pass an atom for t to make the tangent update dynamically:

const tAtom = scene.atom(0);

const tl = tangentLine(scene, {
  f,
  t: tAtom,
  color: "yellow",
});

// Move the tangent along the curve
tAtom.set(Math.PI);

Examples

Interactive Tangent with Curve Point

The most common pattern: combine with curvePoint so dragging the point moves the tangent:

const f = (t: number) => vec3(Math.cos(t), Math.sin(t), t * 0.3);

const { t } = curvePoint(scene, {
  f,
  tStart: 0,
  tEnd: Math.PI * 4,
  initialT: 1.0,
  color: "gold",
});

const tl = tangentLine(scene, {
  f,
  t: t,
  color: "tomato",
  length: 3,
  showPoint: false,
});

Reading the Tangent Direction

The returned tangent atom gives you the raw derivative vector (not normalized), which you can use for further computation:

const tl = tangentLine(scene, { f, t: tAtom });

// Subscribe to the tangent direction
tl.tangent.sub((dir) => {
  console.log("speed:", Vec3.length(dir));
});

Hiding the Point

If you're providing your own point (e.g. from curvePoint), you can hide the one created by the tangent line:

const tl = tangentLine(scene, {
  f,
  t: t,
  showPoint: false,
});

Customizing

The returned items are regular Point3D and Line3D:

const tl = tangentLine(scene, { f, t: 0.5 });

tl.point.radius.set(4);
tl.line.thickness.set(2);

API Reference

Options

PropertyTypeDefaultDescription
f(t: number) => Vec3(required)The parametric function defining the curve
tnumber(required)Parameter value where the tangent is computed
lengthnumber2Total length of the tangent line segment
colorstring"yellow"CSS color string
showPointbooleantrueWhether to show the point on the curve

All options accept either a plain value or an atom.

Returned Handle

FieldTypeDescription
pointPoint3DThe point item on the curve
lineLine3DThe tangent line segment
tangentBoundAtom<Vec3>The tangent vector (derivative) at the current tt
dispose() => voidRemoves all items from the scene

On this page