Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Normalizes (in-place) the specified vector.
     * 
     * @param vector The vector array to normalize.
     * @param vIdx Vector's starting array index.
     */
    public static void normalize(float[] vector, int vIdx) {
        // calculate vector's length
        float length = (float) Math.sqrt(vector[vIdx] * vector[vIdx] + vector[vIdx + 1] * vector[vIdx + 1]
                + vector[vIdx + 2] * vector[vIdx + 2]);

        // divide all components by the vector's length
        vector[vIdx] /= length;
        vector[vIdx + 1] /= length;
        vector[vIdx + 2] /= length;
    }
}