-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoubleVector.java
More file actions
79 lines (63 loc) · 1.49 KB
/
Copy pathDoubleVector.java
File metadata and controls
79 lines (63 loc) · 1.49 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
70
71
72
73
74
75
76
77
78
79
package orbit;
import java.awt.Point;
public class DoubleVector {
private double x,y;
public DoubleVector() {
}
public DoubleVector(DoubleVector otherVector) {
this.x = otherVector.getX();
this.y = otherVector.getY();
}
public DoubleVector(double x, double y) {
this.x = x;
this.y = y;
}
public DoubleVector(int x, int y) {
this.x = x;
this.y = y;
}
//
public void reset() {
this.x = 0;
this.y = 0;
}
public double getX() {
return this.x;
}
public double getY() {
return this.y;
}
public void set(DoubleVector otherVector) {
this.x = otherVector.getX();
this.y = otherVector.getY();
}
public void set(Point otherVector) {
this.x = otherVector.getX();
this.y = otherVector.getY();
}
public DoubleVector get() {
return this;
}
public double getDistance() {
return Math.sqrt(this.x*this.x+this.y*this.y);
}
//
public void addOther(DoubleVector otherVector) {
this.x += otherVector.getX();
this.y += otherVector.getY();
}
public void subtractOther (DoubleVector otherVector) {
this.x -= otherVector.getX();
this.y -= otherVector.getY();
}
public DoubleVector getSum(DoubleVector otherVector) {
return new DoubleVector(this.x+otherVector.x, this.y+otherVector.y);
}
public DoubleVector getMultiply(double ratio) {
return new DoubleVector(this.x*ratio, this.y*ratio);
}
public void multiplyBy(double ratio) {
this.x *= ratio;
this.y *= ratio;
}
}