-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector.js
50 lines (43 loc) · 1 KB
/
vector.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
function Vector2D(x, y) {
this.x = x;
this.y = y;
this.rotate = function(deg) {
var rad = deg * Math.PI/180;
var x = this.x;
var y = this.y;
this.x = x*Math.cos(rad) - y*Math.sin(rad);
this.y = x*Math.sin(rad) + y*Math.cos(rad);
}
this.translate = function(vec) {
this.x += vec.x;
this.y += vec.y;
}
this.itranslate = function(vec) {
this.x -= vec.x;
this.y -= vec.y;
}
this.scale = function(vec) {
this.x *= vec.x;
this.y *= vec.y;
}
this.mult = function(arg) {
if(typeof(arg) == "number") {
this.x *= arg;
this.y *= arg;
}
else {
this.x *= arg.x;
this.y *= arg.y;
}
}
this.div = function(arg) {
if(typeof(arg) == "number") {
this.x /= arg;
this.y /= arg;
}
else {
this.x /= arg.x;
this.y /= arg.y;
}
}
}