If I have some shapes defined using arrays of coordinates e.g.
[[-30, -30], [-30, 30], [30, 30], [30, -30]]
and edges defined using:
You could use a formular for rotating the point around the origin.
function rotate(array, angle) {
return array.map(function (p) {
function r2d(a) { return a * Math.PI / 180; }
return [
Math.cos(r2d(angle)) * p[0] - Math.sin(r2d(angle)) * p[1],
Math.sin(r2d(angle)) * p[0] - Math.cos(r2d(angle)) * p[1],
];
});
}
console.log(rotate([[-30, -30], [-30, 30], [30, 30], [30, -30]], 45));
console.log(rotate([[-30, -30], [-30, 30], [30, 30], [30, -30]], 90));
.as-console-wrapper { max-height: 100% !important; top: 0; }