Repository navigation
Expand file tree
/
Copy pathVector.java
More file actions
69 lines (52 loc) · 1.38 KB
/
Copy pathVector.java
File metadata and controls
69 lines (52 loc) · 1.38 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
public class Vector {
public double x, y, z;
public Vector(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public Vector(double n) {
this.x = n;
this.y = n;
this.z = n;
}
public double getmag() {
return Math.sqrt(this.dot(this));
}
public Vector norm() {
return this.div(this.getmag());
}
public double dot(Vector v) {
return this.x * v.x + this.y * v.y + this.z * v.z;
}
public Vector cross(Vector v) {
return new Vector(this.y * v.z - this.z * v.y, this.z * v.x - this.x * v.z, this.x * v.y - this.y * v.x);
}
public Vector add(Vector v) {
return new Vector(this.x + v.x, this.y + v.y, this.z + v.z);
}
public Vector sub(Vector v) {
return new Vector(this.x - v.x, this.y - v.y, this.z - v.z);
}
public Vector mult(double n) {
return new Vector(this.x * n, this.y * n, this.z * n);
}
public Vector div(double n) {
return new Vector(this.x / n, this.y / n, this.z / n);
}
public String toString() {
return "(" + this.x + ", " + this.y + ", " + this.z + ")";
}
public String toWhiteSpaceString() {
return (int) this.x + " " + (int) this.y + " " + (int) this.z;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getZ() {
return z;
}
}