Calculate magnitude using SensorManager - Android Hardware

Android examples for Hardware:Sensor

Description

Calculate magnitude using SensorManager

Demo Code


//package com.java2s;

import android.hardware.SensorManager;

public class Main {
    public static double[] magnititute(double accx[], double accy[],
            double accz[]) {
        if (!((accx.length == accy.length) && (accy.length == accz.length))) {
            return null;
        }/*  www  .  j av a2  s .  c  om*/
        double result[] = new double[accx.length];
        for (int i = 0; i < accx.length; i++) {
            result[i] = 0.0;
            double grav = SensorManager.GRAVITY_EARTH;
            result[i] += Math.pow(accx[i] / grav, 2.0);
            result[i] += Math.pow(accy[i] / grav, 2.0);
            result[i] += Math.pow(accz[i] / grav, 2.0);
            result[i] = Math.sqrt(result[i]);
            result[i] *= 310;
        }

        return result;
    }
}

Related Tutorials