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

Android examples for java.lang:array calculation

Description

get Euclidean Distance No Sqrt between two float array

Demo Code


//package com.java2s;

public class Main {
    public static float getEuclideanDistanceNoSqrt(float[] v1, float[] v2) {
        if (v1.length != v2.length)
            throw new IllegalArgumentException(
                    "vectors have different lengths! v1=" + v1.length
                            + " and v2=" + v2.length);

        float sum = 0.0f;
        for (int i = 0; i < v1.length; i++) {
            sum += (v1[i] - v2[i]) * (v1[i] - v2[i]);
        }//from   ww w . ja v a 2  s  .  co m
        return sum;
    }
}

Related Tutorials