Dev Helpers
← Back

Rotate a point about an origin

Rotate a point about an origin using JavaScript.

Open this example in the interactive library

Source code

const rotate = ([x, y], r) => [
  x * Math.cos(r) - y * Math.sin(r),
  x * Math.sin(r) + y * Math.cos(r),
];
console.log(rotate([2, 0], Math.PI / 2).map(Math.round));

Sample output

[ 0, 2 ]