?? distance.java
字號:
/**
*
*/
package k_means;
/**
* calculate the distance btween two points
*
* @author xiaoge
*
*/
public class Distance
{
public static Double calDistance(Double[] a,Double[] b)
{
Double Distance;
Double temp = Double.valueOf(0.0);
for (int i = 0; i < b.length - 1; i++)
{
temp += (a[i]-b[i])*(a[i]-b[i]);
}
Distance = Double.valueOf(Math.sqrt(temp.doubleValue()));
return Distance;
}
/**
* calculate the distance between two dimension data whose type is integer
* @param a is the data having two dimension and the type of the data is integer
* @param b is the data having two dimension and the type of the data is integer
* @return
*/
public static double calDis(int[] a,double[] b)
{
double temp = 0.0;
temp = (a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1]) ;
return Math.sqrt(temp);
}
/**
* calculate the distance between two dimension data whose type is double
* @param a is the data having two dimension and the type of the data is double
* @param b is the data having two dimension and the type of the data is double
* @return
*/
public static double calDisDouble(double[] a, double[] b)
{
// TODO Auto-generated method stub
double temp = 0.0;
temp = (a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1]) ;
return Math.sqrt(temp);
}
/**
*
* @param a
* @param b
* @return
*/
public static double calDisPoint(OneData a, OneData b)
{
// TODO Auto-generated method stub
double temp = 0.0;
temp = (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ;
return Math.sqrt(temp);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -