삼변측량법: 3점 좌표와 3점까지의 거리를 통해 4점 위치로 되돌아간다

4827 단어 되돌아오다
 

public class IBeaconLocation {



    //            

    public static double calculateAccuracy(iBeaconClass.iBeacon beacon) {

        int txPower = beacon.txPower;

        double rssi = beacon.rssi;

        if (rssi == 0) {

            return -1.0; // if we cannot determine accuracy, return -1.

        }



        double ratio = rssi * 1.0 / txPower;

        if (ratio < 1.0) {

            return Math.pow(ratio, 10);

        } else {

            double accuracy = (0.89976) * Math.pow(ratio, 7.7095) + 0.111;

            return accuracy;

        }

    }



    //     

    //              ,   4   

    public double[] calcPhonePosition(double x1, double y1, double d1,

                                      double x2, double y2, double d2,

                                      double x3, double y3, double d3) {

        double[] d = {0.0, 0.0};

        double a11 = 2 * (x1 - x3);

        double a12 = 2 * (y1 - y3);

        double b1 = Math.pow(x1, 2) - Math.pow(x3, 2)

                + Math.pow(y1, 2) - Math.pow(y3, 2)

                + Math.pow(d3, 2) - Math.pow(d1, 2);

        double a21 = 2 * (x2 - x3);

        double a22 = 2 * (y2 - y3);

        double b2 = Math.pow(x2, 2) - Math.pow(x3, 2)

                + Math.pow(y2, 2) - Math.pow(y3, 2)

                + Math.pow(d3, 2) - Math.pow(d2, 2);



        d[0] = (b1 * a22 - a12 * b2) / (a11 * a22 - a12 * a21);

        d[1] = (a11 * b2 - b1 * a21) / (a11 * a22 - a12 * a21);



        return d;



    }



    //double     

    public int doubleRound(double num) {

        BigDecimal b = new BigDecimal(num);

        num = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();

        return (int) num;

    }



}

좋은 웹페이지 즐겨찾기