Java Array Normalize normalize(float p[])

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

Description

normalize

License

Open Source License

Declaration

public static float normalize(float p[]) 

Method Source Code

//package com.java2s;
/*//  w w w  . j  a v  a  2s  . c  o  m
 * @(#)gl_util.java 0.3 06/11/20
 *
 * jGL 3-D graphics library for Java
 * Copyright (c) 1999-2006 Robin Bing-Yu Chen (robin@ntu.edu.tw)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version. the GNU Lesser
 * General Public License should be included with this distribution
 * in the file LICENSE.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

public class Main {
    public static float normalize(float p[]) {
        float w = (float) Math.sqrt(p[0] * p[0] + p[1] * p[1] + p[2] * p[2]);
        if (w > 0.000001f) {
            p[0] /= w;
            p[1] /= w;
            p[2] /= w;
        }
        return w;
    }
}

Related

  1. normalize(final double[] doubles)
  2. normalize(final double[] fir)
  3. normalize(final double[] tab)
  4. normalize(final double[] vec)
  5. normalize(final double[] vector, final double[] minima, final double[] maxima)
  6. normalize(float[] data)
  7. normalize(float[] in)
  8. normalize(float[] in)
  9. normalize(float[] input)