← Back to index

Circumference point

Given a line from the origin of a circle, find the point where it intersects the circumference. Move the mouse over the canvas.

See also: Tangent lines from an external point — uses the same centre + r·(cosθ, sinθ), with θ offset by ±acos(r/d).

Pseudocode

a = atan2(target.y - origin.y, target.x - origin.x)
cX = origin.x + cos(a) * radius
cY = origin.y + sin(a) * radius

Source

const originX = 150
const originY = 150
const circleRadius = 75

// angle from origin towards the mouse
const a = Math.atan2(mouseY - originY, mouseX - originX)

// intersection with circumference
const cX = originX + Math.cos(a) * circleRadius
const cY = originY + Math.sin(a) * circleRadius