- Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathDistance.java
31 lines (26 loc) · 869 Bytes
/
Distance.java
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
packagecom.jwetherell.algorithms.mathematics;
publicclassDistance {
privateDistance() { }
/*
* Chess distance
*/
publicstaticfinallongchebyshevDistance(long[] point1, long[] point2) {
longx1 = point1[0];
longy1 = point1[1];
longx2 = point2[0];
longy2 = point2[1];
returnMath.max(Math.abs(x1 - x2), Math.abs(y1 - y2));
}
publicstaticfinaldoublesquaredDistance(doublex1, doubley1, doublex2, doubley2) {
doublex = x1 - x2;
doubley = y1 - y2;
doublesqr = (x * x) + (y * y);
returnsqr;
}
publicstaticfinaldoubleeuclideanDistance(doublex1, doubley1, doublex2, doubley2) {
doublex = Math.pow((x1 - x2), 2);
doubley = Math.pow((y1 - y2), 2);
doublesqrt = Math.sqrt(x + y);
returnsqrt;
}
}