Find the midpoint of a line between two points. Move the mouse over the canvas.
See also: Point along a line (lerp) — a midpoint is just lerp at t = 0.5.
length = sqrt(dx * dx + dy * dy)
a = atan2(dy, dx)
midX = originX + cos(a) * length / 2
midY = originY + sin(a) * length / 2
const originX = 150
const originY = 150
const dx = mouseX - originX
const dy = mouseY - originY
const length = Math.sqrt(dx * dx + dy * dy)
const a = Math.atan2(dy, dx)
const midX = originX + Math.cos(a) * length / 2
const midY = originY + Math.sin(a) * length / 2
// Equivalent shorter form:
// const midX = (originX + mouseX) / 2
// const midY = (originY + mouseY) / 2