I have a problem understanding the formula for rotating a point around another point.
On one side we have this code taken from here (a very popular answer from stackoverflow).
function rotate_point_1(pointX, pointY, originX, originY, angle) {
angle = angle * Math.PI / 180.0;
return {
x: Math.cos(angle) * (pointX-originX) - Math.sin(angle) * (pointY-originY) + originX,
y: Math.sin(angle) * (pointX-originX) + Math.cos(angle) * (pointY-originY) + originY
};
}
And on the other hand this one from here (another very popular answer), I just changed it a bit to make it very similar as the first one.
function rotate_point_2(pointX, pointY, originX, originY, angle) {
angle = angle * Math.PI / 180.0;
return {
x: Math.cos(angle) * (pointX-originX) + Math.sin(angle) * (pointY-originY) + originX,
y: Math.cos(angle) * (pointY-originY) - Math.sin(angle) * (pointX-originX) + originY
}
}
When calling such formulas with small data the answer does not change too much, but when using complex quantities like the following:
consr r1 = rotate_point_1(-2682.124970310381, 1284.7120051002187, 2947.162670759748, 1163.2594358745218, -90);
const r2= rotate_point_2(-2682.124970310381, 1284.7120051002187, 2947.162670759748, 1163.2594358745218, -90)
The results are different:
r1 = {x: 3068.615239985446, y: 6792.54707694465}
r2 = {x: 3068.615239985446, y: 1041.8068666488261}
Which of both is the correct to use?
Thanks in advance.