Advertisement
stuppid_bot

Rotate point around another point

Dec 26th, 2016
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function rotatePoint(point, pivot, angle) {
  2.   let dx = point.x - pivot.x;
  3.   let dy = point.y - pivot.y;
  4.   let radians = angle * DEG2RAD;
  5.   let sin = Math.sin(radians);
  6.   let cos = Math.cos(radians);
  7.   let x = Math.round(pivot.x + cos * dx - sin * dy);
  8.   let y = Math.round(pivot.y + sin * dx + cos * dy);
  9.   return new Point(x, y);
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement