Calculates the magnitude of any vector by using Pythagorean principle. - Android java.lang

Android examples for java.lang:Math Vector

Description

Calculates the magnitude of any vector by using Pythagorean principle.

Demo Code


//package com.java2s;

public class Main {
    /**//from www  .j  ava2  s  .  c  o m
     * Calculates the magnitude of any vector by using Pythagorean principle.
     * 
     * @param vectorComponents
     * @return The vector magnitude.
     */
    public static double getVectorMagnitude(float[] vectorComponents) {
        double result = 0;
        for (double d : vectorComponents) {
            result += Math.pow(d, 2);
        }
        return Math.sqrt(result);
    }
}

Related Tutorials