Java Matrix Square sqrEuclidianDist(float[] p, float[] q)

Here you can find the source of sqrEuclidianDist(float[] p, float[] q)

Description

Squared Euclidian distance of p and q.

License

Apache License

Parameter

Parameter Description
p First euclidian point coordinates.
q Second euclidian point coordinates. Dimension must not be smaller than that of p. Any extra dimensions will be ignored.

Return

Squared euclidian distance of p and q.

Declaration

public static float sqrEuclidianDist(float[] p, float[] q) 

Method Source Code

//package com.java2s;
/*//w ww  .  java2  s.c  o  m
 Copyright 2005, 2006 by Gerald Friedland and Kristian Jantz

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

public class Main {
    /**
     * Squared Euclidian distance of p and q.
     * <P>
     * Usage hint: When only comparisons between Euclidian distances without
     * actual values are needed, the squared distance can be preferred
     * for being faster to compute.
     *
     * @param p First euclidian point coordinates.
     * @param q Second euclidian point coordinates.
     *        Dimension must not be smaller than that of p.
     *        Any extra dimensions will be ignored.
     * @return Squared euclidian distance of p and q.
     * @see #euclid
     */
    public static float sqrEuclidianDist(float[] p, float[] q) {
        float sum = 0;
        for (int i = 0; i < p.length; i++) {
            sum += (p[i] - q[i]) * (p[i] - q[i]);
        }
        return sum;
    }
}

Related

  1. sqr(double[] a, double res[])
  2. sqrdist(float[] a, float[] b)
  3. sqrt(double[] v)
  4. sqrt(double[] vector)