Java Array Normalize normalize(float[] v)

Here you can find the source of normalize(float[] v)

Description

Normalize vector

License

Open Source License

Parameter

Parameter Description
v a parameter

Return

float[]

Declaration

protected static float[] normalize(float[] v) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   ww  w.j a  v  a2  s.co  m
     * Normalize vector
     *
     * @param v
     *
     * @return float[]
     */
    protected static float[] normalize(float[] v) {
        float r;

        r = (float) Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
        if (r == 0.0)
            return v;

        r = 1.0f / r;

        v[0] *= r;
        v[1] *= r;
        v[2] *= r;

        return v;
    }
}

Related

  1. normalize(float p[])
  2. normalize(float[] data)
  3. normalize(float[] in)
  4. normalize(float[] in)
  5. normalize(float[] input)
  6. normalize(float[] vec)
  7. normalize(float[][] vals, float min, float max)
  8. normalize(int[] a)
  9. normalize(int[] values)