-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.java
More file actions
67 lines (59 loc) · 1.28 KB
/
Vector.java
File metadata and controls
67 lines (59 loc) · 1.28 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
/**
* Base class for all vector measurements
*
* @author Austin
* @version 0
*/
public class Vector {
protected double x;
protected double y;
/**
* Constructor for Vector
*
* @param x The x component of the vector
* @param y The y component of the vector
*/
public Vector(double x, double y) {
this.x = x;
this.y = y;
}
/**
* Get the magnitude of the vector
*
* @return The magnitude of the vector
*/
public double getMagnitude() {
return Math.hypot(x, y);
}
/**
* Get the angle of the vector
*
* @return The angle of the vector in radians (0 for y = 0 and x > 0)
*/
public double getAngle() {
return Math.atan2(y, x);
}
// Getters
public double getX() {
return x;
}
public double getY() {
return y;
}
// Setters
public void setX(double x) {
this.x = x;
}
public void setY(double y) {
this.y = y;
}
/**
* Add two Vectors
*
* @param other Another vector
* @return The resultant vector
*/
public Vector add(Vector other) {
return new Vector(x + other.getX(), y + other.getY());
}
}