-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotate.js
66 lines (55 loc) · 1.56 KB
/
rotate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function toDegrees(num) {
return num * (180 / Math.PI);
}
function toRadians(num) {
return num * (Math.PI / 180);
}
function rotatePoint(oX, oY, rX, rY, rotDeg) {
if (oX == rX && oY == rY) {
return [rX, rY];
}
Xposneg = Math.sign((rX + .1) - oX);
Yposneg = Math.sign((rY + .1) - oY);
rotDeg = rotDeg * (Math.sign(Xposneg * Yposneg) * -1);
// //PP
// if (rX >= oX && rY >= oY) {
// rotDeg = rotDeg * -1;
// Xposneg = 1;
// Yposneg = 1;
// }
// //NN
// if (rX < oX && rY < oY) {
// rotDeg = rotDeg * -1;
// Xposneg = -1;
// Yposneg = -1;
// }
// //PN
// if (rX >= oX && rY < oY) {
// Xposneg = 1;
// Yposneg = -1;
// }
// //NP
// if (rX < oX && rY >= oY) {
// Xposneg = -1;
// Yposneg = 1;
// }
opo = Math.abs(oY - rY);
adj = Math.abs(oX - rX);
// drawpoint(oX, oY, "O");
// drawpoint(rX, rY, "R");
hypo = Math.sqrt(opo ** 2 + adj ** 2);
current_angle = toDegrees(Math.atan(opo / adj));
next_angle = current_angle + rotDeg;
testY = (Math.sin(toRadians(next_angle)) * hypo);
testX = (Math.cos(toRadians(next_angle)) * hypo);
x = oX + (testX * Xposneg);
y = oY + (testY * Yposneg);
return [x, y];
}
function rotatePoints(array, oX, oY, deg, axis1, axis2) {
for (point = 0; point < array.length; point++) {
rot = rotatePoint(oX, oY, array[point][axis1], array[point][axis2], deg);
array[point][axis1] = rot[0];
array[point][axis2] = rot[1];
}
}