Here you can find the source of normalise(float[] array)
Parameter | Description |
---|---|
array | the array |
public static void normalise(float[] array)
//package com.java2s; public class Main { /**// ww w .ja va 2s. co m * Normalise length of array to 1.0. Writes over array * * @param array the array */ public static void normalise(float[] array) { float sumsq = 0.0f; for (int i = 0; i < array.length; i++) sumsq += array[i] * array[i]; float weight = 1.0f / (float) Math.sqrt(sumsq); for (int i = 0; i < array.length; i++) array[i] *= weight; } /** * Normalise length of array to 1.0. Writes over array * * @param array the array */ public static void normalise(double[] array) { double sumsq = 0.0f; for (int i = 0; i < array.length; i++) sumsq += array[i] * array[i]; double weight = 1.0f / Math.sqrt(sumsq); for (int i = 0; i < array.length; i++) array[i] *= weight; } }