mirror of
https://github.com/Febbweiss/sis.git
synced 2026-03-04 22:25:35 +00:00
Feature: adding wave 3 and 4 + new moves : half_part_rotation & rotation
This commit is contained in:
45
js/tools.js
45
js/tools.js
@@ -22,3 +22,48 @@ function heriter(destination, source) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function distance(point1, point2) {
|
||||
return Math.sqrt(Math.pow(point2.x - point1.x, 2) + Math.pow(point2.y - point1.y, 2));
|
||||
}
|
||||
|
||||
function normalize(vector) {
|
||||
var norm = Math.sqrt(vector.x * vector.x + vector.y * vector.y);
|
||||
if (norm == 0)
|
||||
return {
|
||||
x : 0,
|
||||
y : 0
|
||||
};
|
||||
|
||||
var x = vector.x / norm;
|
||||
var y = vector.y / norm;
|
||||
return {
|
||||
x : x,
|
||||
y : y
|
||||
}
|
||||
}
|
||||
|
||||
function angle(vector1, vector2) {
|
||||
if ((vector1.x == 0 && vector1.y == 0)
|
||||
&& (vector1.x == 0 && vector1.y == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vector1.x == 0 && vector1.y == 0) {
|
||||
return Math.acos(vector2.x
|
||||
/ Math.sqrt(vector2.x * vector2.x + vector2.y * vector2.y));
|
||||
}
|
||||
|
||||
if (vector2.x == 0 && vector2.y == 0) {
|
||||
return Math.acos(vector1.x
|
||||
/ Math.sqrt(vector1.x * vector1.x + vector1.y * vector1.y));
|
||||
}
|
||||
|
||||
var product = vector1.x * vector2.x + vector1.y * vector2.y,
|
||||
alpha = Math.acos(product
|
||||
/ (Math.sqrt(vector1.x * vector1.x + vector1.y * vector1.y) * Math
|
||||
.sqrt(vector2.x * vector2.x + vector2.y * vector2.y))),
|
||||
sign = normalize(vector1).y > normalize(vector2).y ? -1 : 1;
|
||||
|
||||
return sign * alpha;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user