distance.java
来自「上传试试看 不知道 是不是一定成功的」· Java 代码 · 共 69 行
JAVA
69 行
/**
*
*/
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 + =
减小字号Ctrl + -
显示快捷键?