Repository navigation
Expand file tree
/
Copy pathPair.java
More file actions
68 lines (67 loc) · 1.64 KB
/
Copy pathPair.java
File metadata and controls
68 lines (67 loc) · 1.64 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
import java.lang.Math;
/**
* the class is used to interpret
* properties having x and y components
* @author ikramgabiyev
*
*/
public class Pair {
//variables
public double x; //individual x coordinate
public double y; //individual y coordinate
public Pair(double _x, double _y) {
this.x = _x;
this.y = _y;
}
/**
* adds individual components of pairs
* @param _addedPair
* @return a new pair
*/
public Pair add(Pair _addedPair) {
double finalX = this.x + _addedPair.x;
double finalY = this.y + _addedPair.y;
return new Pair(finalX, finalY);
}
/**
* subtracts individual components of two pairs
* @param _subtractingPair
* @return a new pair
*/
public Pair subtract(Pair _subtractingPair) {
double finalX = this.x - _subtractingPair.x;
double finalY = this.y - _subtractingPair.y;
return new Pair(finalX, finalY);
}
/**
* if you enter a pair as a parameter
* it multiplies each component of this pair
* by those of the parameter
* @param _multipliedPair
* @return
*/
public Pair times(Pair _multipliedPair) {
double finalX = this.x * _multipliedPair.x;
double finalY = this.y * _multipliedPair.y;
return new Pair(finalX, finalY);
}
/**
* if you enter a double as a parameter
* it multiplies each component of this pair
* by that multiple
* @param _multipliedPair
* @return
*/
public Pair times(double _multiple) {
double finalX = this.x * _multiple;
double finalY = this.y * _multiple;
return new Pair(finalX, finalY);
}
/**
* Gives you the length of the 2D vector
* @return magnitude
*/
public double getMagnitude() {
return Math.sqrt(this.x*this.x + this.y*this.y);
}
}