Java Array Normalize normalize(double[] points)

Here you can find the source of normalize(double[] points)

Description

Normalizes a vector

License

Open Source License

Parameter

Parameter Description
points a parameter

Return

points / || points ||

Declaration

public static double[] normalize(double[] points) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//w ww.j a v  a2 s .  c o  m
     * Normalizes a vector
     * 
     * @param points
     * @return points / || points ||
     */
    public static double[] normalize(double[] points) {
        double length = length(points);
        for (int i = 0; i < points.length; i++) {
            points[i] = points[i] / length;
        }
        return points;
    }

    public static double length(double[] point) {
        return Math.sqrt(stScalarProd(point, point));
    }

    /**
     * Standard Skalarprodukt to UnitMatrix.
     * 
     * @param a first vector
     * @param b second vector
     * @return <a,b>
     */
    public static double stScalarProd(double[] a, double[] b) {
        if (a.length != b.length)
            throw new IllegalArgumentException("Multiplied two Vectors of different length.");

        double sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i] * b[i];
        }
        return sum;
    }
}

Related

  1. normalize(double[] doubles, double sum)
  2. normalize(double[] doubles, double sum)
  3. normalize(double[] in)
  4. normalize(double[] in)
  5. normalize(double[] point, double[] uni, double[] unideltas)
  6. normalize(double[] probDist)
  7. normalize(double[] state)
  8. normalize(double[] v)
  9. normalize(double[] v)