Integral jarak

mail@pastecode.io avatar
unknown
java
2 years ago
2.0 kB
5
Indexable
Never
    public Double Calculate(float time, float[] acceleration){
        if (acceleration.length>2 ){
            if (acceleration[2] < pref.getFloat("upper",3) &&
                    acceleration[2] > pref.getFloat("lower",-3)){
                DataCSV data = new DataCSV(Double.valueOf(time), Double.valueOf(acceleration[0]),
                        Double.valueOf(acceleration[1]), Double.valueOf(acceleration[2]));
                dataAsli.add(data);
                //Integral Kecepatan
                if (a==0){
                    temp = 0;
                    b = b+temp;
                    listkecepatan.add(new DataCSV(0.0,b));
                }else{
                    temp = (((dataAsli.get(a).getZ()+dataAsli.get(a-1).getZ())*(dataAsli.get(a).getTimestamp()-dataAsli.get(a-1).getTimestamp()))/2);
                    b = b+temp;
                    DataCSV data_v = new DataCSV(dataAsli.get(a).getTimestamp(), b);
                    listkecepatan.add(data_v);
                }
                if (i==0){
                    temp = 0;// listkecepatan.get(i).getZ();
                    c = c + temp;
                    DataCSV data_s = new DataCSV(listkecepatan.get(i).getTimestamp(), c);
                    listjarak.add(data_s);
                }else {
                    temp = (((listkecepatan.get(i).getZ()+listkecepatan.get(i-1).getZ())*(dataAsli.get(i).getZ()-dataAsli.get(i-1).getZ()))/2);
                    c = c + temp;
                    DataCSV data_s = new DataCSV(listkecepatan.get(i).getTimestamp(), c);
                    listjarak.add(data_s);
                }
                a = a+1;
                i = i +1;
                //Integral Jarak
//                listjarak = IntegralJarak(listkecepatan, dataAsli);
//                Log.i("dataaa", acceleration[2]+"-"+a );
                jarak = listjarak.get(listjarak.size()-1).getZ();
                return jarak;
            }
        }
        return 0.0;
    }