get Euclidean Distance between two float array - Android java.lang

Android examples for java.lang:array calculation

Description

get Euclidean Distance between two float array

Demo Code


import java.util.List;
import android.util.FloatMath;

public class Main{
    public static float getEuclideanDistance(float[] v1, float[] v2) {
        float sum = 0.0f;
        for (int i = 0; i < v1.length; i++) {
            sum += (v1[i] - v2[i]) * (v1[i] - v2[i]);
        }/*from w  w  w. j av a  2 s  .  c o  m*/
        return FloatMath.sqrt(sum);
    }
}

Related Tutorials