Here you can find the source of normalize(double[] v)
public static double[] normalize(double[] v)
//package com.java2s; //License from project: Open Source License public class Main { /** returns vector v normalized */ public static double[] normalize(double[] v) { double[] v0 = new double[3]; double n = norm(v); v0[0] = v[0] / n;/*from w w w .j a va2s . co m*/ v0[1] = v[1] / n; v0[2] = v[2] / n; return (v0); } /** returns the norm of the vector*/ public static double norm(double[] v) { return (Math.sqrt(dotprod(v, v))); } /** computes the dot product v1*v2.*/ public static double dotprod(double[] v1, double[] v2) { return (v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]); } }