If I have some shapes defined using arrays of coordinates e.g.
[[-30, -30], [-30, 30], [30, 30], [30, -30]]
and edges defined using:
Here you go, rotates point x, y
around point centerx, centery
by degrees
degrees. Returns floating values, round if you need to.
To rotate a shape, rotate all the points. Calculate the center if you need to, this does not do it.
Desmos link with x as a, y as b, centerx as p, centery as q, and degrees as s
function rotatePoint(x, y, centerx, centery, degrees) {
var newx = (x - centerx) * Math.cos(degrees * Math.PI / 180) - (y - centery) * Math.sin(degrees * math.PI / 180) + centerx;
var newy = (x - centerx) * Math.sin(degrees * Math.PI / 180) + (y - centery) * Math.cos(degrees * math.PI / 180) + centery;
return [newx, newy];
}