Skip to content

Home

Midpoint

Calculates the midpoint between two pairs of (x,y) points.

const midpoint = ([x1, y1], [x2, y2]) => [(x1 + x2) / 2, (y1 + y2) / 2];

midpoint([2, 2], [4, 4]); // [3, 3]
midpoint([4, 4], [6, 6]); // [5, 5]
midpoint([1, 3], [2, 4]); // [1.5, 3.5]

More like this

Start typing a keyphrase to see matching snippets.