Mega Code Archive

 
Categories / Android / Game
 

Compute the magnitude (length) of a vector

class Main {   /**    * Compute the magnitude (length) of a vector    *     * @param vector    *            The vector    * @return The magnitude of the vector    **/   public static float magnitude(float[] vector) {     return (float) Math.sqrt(vector[0] * vector[0] + vector[1] * vector[1]         + vector[2] * vector[2]);   } }