📄 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 + -