Calculates the magnitude of a vector by using Pythagorean principle without the Z element. - Android java.lang

Android examples for java.lang:Math Vector

Description

Calculates the magnitude of a vector by using Pythagorean principle without the Z element.

Demo Code


//package com.java2s;

public class Main {
    /**/*from w  w  w. j a  v a 2  s  . com*/
     * Calculates the magnitude of a vector by using Pythagorean principle
     * without the Z element.
     * 
     * @param vectorComponents
     * @return The vector magnitude minus Z element.
     */
    public static double getVectorMagnitudeMinusZ(float[] vectorComponents) {
        double result = 0;
        for (int i = 0; i < 2; i++) {
            result += Math.pow(vectorComponents[i], 2);
        }
        return Math.sqrt(result);
    }

    /**
     * Calculates the magnitude of a vector by using Pythagorean principle
     * without the Z element.
     * 
     * @param vectorComponents
     * @return The vector magnitude minus Z element.
     */
    public static double getVectorMagnitudeMinusZ(double vectorComponentX,
            double vectorComponentY) {
        double result = Math.pow(vectorComponentX, 2)
                + Math.pow(vectorComponentY, 2);
        return Math.sqrt(result);
    }
}

Related Tutorials