-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEuclideanPoint_MiS.java
More file actions
33 lines (32 loc) · 1.12 KB
/
EuclideanPoint_MiS.java
File metadata and controls
33 lines (32 loc) · 1.12 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
public class EuclideanPoint_MiS{
private int dimension;
private double[] coordinates;
private double[] mid;
public EuclideanPoint_MiS(double[] coordinates){
dimension = coordinates.length;
this.coordinates = coordinates;
}
public double getDimension(){
return dimension;
}
public double distanceTo(EuclideanPoint_MiS q){
double sum = 0;
//if the two points are not in the same dimension, do not conduct the operation
if(this.getDimension() != q.getDimension()){
throw new java.lang.RuntimeException("The two points are not in the same dimension");
}
else{//subtracts the two and squares the result
for(int i = 0; i < dimension; i++){
sum += Math.pow(this.coordinates[i] - q.coordinates[i], 2);
}
}//returns the square root
return Math.sqrt(sum);
}
public double[] midPoint(EuclideanPoint_MiS q){
double[] mid = new double[coordinates.length];
for (int i = 0; i < dimension; i++) {
mid[i] = (this.coordinates[i] + q.coordinates[i]) / 2; //Average each coordinate and assign to the index in the new array
}
return mid;//retun whole new array
}
}