← Back to index

Point-in-circle (hit test)

A point is inside a circle when its squared distance to the centre is less than the radius squared. No square root needed for the test itself.

See also: Distance between two points — the same calculation, taking the square root for the actual distance.

Pseudocode

dx = p.x - c.x
dy = p.y - c.y
inside = dx * dx + dy * dy <= r * r

Source

const cx = 150, cy = 150, r = 80

const dx = mouseX - cx
const dy = mouseY - cy
const inside = (dx * dx + dy * dy) <= r * r