public class Vector2D private double private double public double getX

 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
public class Vector2D {
private double x;
private double y;
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public Vector2D() {
this(0,0);
}
public Vector2D (double x, double y) {
this.x = x;
this.y = y;
}
public Vector2D add (Vector2D vector) {
return new Vector2D (x + vector.getX(), y + vector.getY());
}
public void add2 (Vector2D vector) {
this.x += vector.getX();
}
public Vector2D sub (Vector2D vector) {
return new Vector2D (x + vector.getX(), y + vector.getY());
}
public void sub2 (Vector2D vector) {
this.x -= vector.getX();
}
public Vector2D mult (double a) {
return new Vector2D (x * a, y * a);
}
public void mult2 (double a) {
this.x *= a;
this.y *= a;
}
public String toString() {
return ("(" + x + ", " + y + ")");
}
public double length() {
return Math.sqrt(x * x + y * y);
}
public double scalarProduct (Vector2D vector) {
return x * vector.getX() + y * vector.getY();
}
public double cos (Vector2D vector) {
double c = scalarProduct(vector);
double d = length();
return Math.cos(c / d);
}
public boolean equals (Vector2D vector) {
return (x == vector.getX() && y == vector.getY());
}
}