Feature: adding wave 3 and 4 + new moves : half_part_rotation & rotation

This commit is contained in:
Fabrice Ecaille
2013-10-30 18:25:34 +01:00
parent c7e48ca390
commit be0c33a034
3 changed files with 173 additions and 31 deletions

View File

@@ -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;
}