-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathVector.pde
More file actions
45 lines (35 loc) · 695 Bytes
/
Copy pathVector.pde
File metadata and controls
45 lines (35 loc) · 695 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
40
41
42
43
44
45
class Vector {
float x, y;
public Vector(float x, float y) {
this.x = x;
this.y = y;
}
String toString() {
return "<" + nf(this.x, 1, 6) + ", " + nf(this.y, 1, 6) + ">";
}
Vector copy() {
return new Vector(x, y);
}
boolean equals(Vector other) { return x == other.x && y == other.y; }
void add(Vector b) {
x += b.x;
y += b.y;
}
void sub(Vector b) {
x -= b.x;
y -= b.y;
}
void mult(float scalar) {
x *= scalar;
y *= scalar;
}
float magSquared() {
return x * x + y * y;
}
float mag() {
return (float) Math.sqrt(magSquared());
}
void normalize() {
mult(1 / ((float) Math.sqrt(magSquared())));
}
}