- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathVector2.js
More file actions
Latest commit
39 lines (29 loc) · 860 Bytes
/
Copy pathVector2.js
File metadata and controls
39 lines (29 loc) · 860 Bytes
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
functionVector2(x=0,y=0){
this.x=x;
this.y=y;
}
Vector2.prototype.copy=function(){
returnnewVector2(this.x,this.y);
}
Vector2.prototype.add=function(vector){
returnnewVector2(this.x+vector.x,this.y+vector.y);
}
Vector2.prototype.addTo=function(vector){
this.x+=vector.x;
this.y+=vector.y;
}
Vector2.prototype.subtract=function(vector){
returnnewVector2(this.x-vector.x,this.y-vector.y);
}
Vector2.prototype.mult=function(scalar){
returnnewVector2(this.x*scalar,this.y*scalar);
}
Vector2.prototype.dot=function(vector){
returnthis.x*vector.x+this.y*vector.y;
}
Vector2.prototype.length=function(){
returnMath.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2));
}
Vector2.prototype.distFrom=function(vector){
returnthis.subtract(vector).length();
}