Here you can find the source of normalize(double[] a)
public static double[] normalize(double[] a)
//package com.java2s; //License from project: Open Source License public class Main { public static double[] normalize(double[] a) { double l = length(a); if (l < 0.1) { l = 0.1;//from w ww . ja va 2 s. c om } double[] v = new double[a.length]; for (int i = 0; i < a.length; ++i) { v[i] = a[i] / l; } return v; } public static double length(double[] v) { return Math.sqrt(lengthSquare(v)); } public static double lengthSquare(double[] v) { double s = 0; for (double x : v) { s += x * x; } return s; } }