raw Math

Let a circle have center \(\mathbf{M}=(m_x,m_y)\), radius \(r>0\), and a point \(\mathbf{T}\) on its boundary. The tangent at \(\mathbf{T}\) is the unique line through \(\mathbf{T}\) perpendicular to the radius \(\mathbf{T}-\mathbf{M}\). This perpendicularity is the entire construction.

Move the mouse over the plot to position \(\mathbf{T}\) and its perpendicular tangent.

Locating the Tangency Point

Parameterize the radius direction by the usual Cartesian unit vector

\[\mathbf{u}(\alpha)=\begin{pmatrix}\cos\alpha\\\sin\alpha\end{pmatrix}.\]

The point at angle \(\alpha\) is therefore

\[\mathbf{T}=\mathbf{M}+r\mathbf{u}(\alpha)=\begin{pmatrix}m_x+r\cos\alpha\\m_y+r\sin\alpha\end{pmatrix}.\]

Notice the coordinate order: cosine supplies the horizontal component and sine the vertical component. For \(\alpha=0\), the point lies to the right of the center; for \(\alpha=\pi/2\), it lies above it in a Cartesian coordinate system.

Constructing a Perpendicular Direction

The radius direction is \(\mathbf{u}(\alpha)\). Rotating any vector \((x,y)\) counterclockwise by \(90^\circ\) maps it to \((-y,x)\), so a unit direction vector along the tangent is

\[\mathbf{v}(\alpha)=\begin{pmatrix}-\sin\alpha\\\cos\alpha\end{pmatrix}.\]

Its dot product with the radial unit vector vanishes:

\[\mathbf{u}(\alpha)\cdot\mathbf{v}(\alpha)=-\cos\alpha\sin\alpha+\sin\alpha\cos\alpha=0.\]

Thus the tangent line in parametric form is

\[\boxed{\mathbf{L}(s)=\mathbf{T}+s\mathbf{v}(\alpha),\qquad s\in\mathbb{R}.}\]

The parameter \(s\) measures signed distance along the line because \(\mathbf{v}\) has unit length. Replacing \(\mathbf{v}\) by \(-\mathbf{v}\) describes the same unoriented line.

Implicit and Slope Forms

A point \(\mathbf{X}=(x,y)\) lies on the tangent precisely when its displacement from \(\mathbf{T}\) is perpendicular to the radius. This gives the implicit equation

\[(\mathbf{X}-\mathbf{T})\cdot(\mathbf{T}-\mathbf{M})=0.\]

Since \(\mathbf{T}-\mathbf{M}=r(\cos\alpha,\sin\alpha)\), it becomes

\[\boxed{(x-T_x)\cos\alpha+(y-T_y)\sin\alpha=0.}\]

When \(\sin\alpha\ne0\), solving for \(y\) yields

\[y-T_y=-\cot(\alpha)(x-T_x).\]

At \(\alpha=0\) or \(\alpha=\pi\), the radius is horizontal and the tangent is vertical, so slope form is undefined. The vector and implicit forms remain valid without a special case.

Implementation

The calculation needs only the center, radius, and angle. Returning a point and a unit direction keeps vertical tangents representable and avoids slope singularities.

function tangentLine(center, radius, angle) {
  if (!(radius > 0)) {
    throw new RangeError("The radius must be positive");
  }

  const cosine = Math.cos(angle);
  const sine = Math.sin(angle);

  return {
    point: {
      x: center.x + radius * cosine,
      y: center.y + radius * sine
    },
    direction: {
      x: -sine,
      y: cosine
    }
  };
}

If the boundary point \(\mathbf{T}\) is known instead of the angle, first verify that \(|\mathbf{T}-\mathbf{M}|=r\) within the chosen numerical tolerance. Then normalize \(\mathbf{T}-\mathbf{M}\) and rotate the resulting unit vector by \(90^\circ\) in exactly the same way.