예제 #1
0
        //RelativeLayout.LayoutParams par;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);
            var imageView = FindViewById<ImageView> (Resource.Id.demoImageView);
            ImageView dot = (ImageView) FindViewById(Resource.Drawable.positionCursor);

            var b1 = new iBeacon();
            var b2 = new iBeacon();
            var b3 = new iBeacon();

            b1.X = 200;
            b1.Y = 100;
            b2.X = 290;
            b2.Y = 520;
            b3.X = 20;
            b3.Y = 1000;

            var dotpos = tr.Trilaterate (b1, b2, b3);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            //AbsoluteLayout.LayoutParams param = new AbsoluteLayout.LayoutParams (10, 10, 100, 200);
            //dot.setLayoutParam(param);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button> (Resource.Id.myButton);
            button.Click += delegate {

            };
        }
        //RelativeLayout.LayoutParams par;


        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);



            var b1 = new iBeacon();
            var b2 = new iBeacon();
            var b3 = new iBeacon();

            b1.Distance = 3;
            b2.Distance = 3;
            b3.Distance = 3;

            b1.RSSI = -50;
            b2.RSSI = -50;
            b3.RSSI = -50;

            b1.X = 200;
            b1.Y = 100;
            b2.X = 290;
            b2.Y = 520;
            b3.X = 20;
            b3.Y = 1000;

            var dotpos = tr.Trilaterate(b1, b2, b3);


            //Din mamma

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            //AbsoluteLayout.LayoutParams param = new AbsoluteLayout.LayoutParams (10, 10, 100, 200);
            //dot.setLayoutParam(param);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById <Button> (Resource.Id.myButton);

            button.Click += delegate {
                ImageView dot = FindViewById <ImageView> (Resource.Id.dotID);
                dot.SetImageResource(Resource.Drawable.positionCursor);
                dot.Right = 20;
                dot.Top   = 20;
            };
        }
예제 #3
0
        public Position Trilaterate(iBeacon beacon1, iBeacon beacon2, iBeacon beacon3)
        {
            //Dessa tre används för att förenkla beräkningen
            var tmpWAP1 = new iBeacon();
            var tmpWAP2 = new iBeacon();
            var tmpWAP3 = new iBeacon();

            double tmpLat2, tmpLong2, tmpLat3, tmpLong3;
            double tmpSlide, deg;
            double MyLat, MyLong;

            var MyPosition = new Position();

            //Utgå från att Lat1 är origo
            tmpLat2 = beacon2.X - beacon1.X;
            tmpLong2 = beacon2.Y - beacon1.Y;
            tmpLat3 = beacon3.X - beacon1.X;
            tmpLong3 = beacon3.Y - beacon1.Y;

            tmpSlide = Math.Sqrt(Math.Pow(tmpLat2, 2) + Math.Pow(tmpLong2, 2));

            //deg = (180/Math.PI)*Math.acos( ((Math.Pow(tmpLat2,2) + Math.Pow(tmpSlide,2) - Math.Pow(tmpLong2, 2)) / (2*tmpLat2*tmpSlide)) );
            deg = (180 / Math.PI) * Math.Acos(Math.Abs(tmpLat2) / Math.Abs(tmpSlide));

            // 1 quadrant
            if ((tmpLat2 > 0 && tmpLong2 > 0))
            {
                deg = 360 - deg;
            }
            else if ((tmpLat2 < 0 && tmpLong2 > 0))
            {
                deg = 180 + deg;
            }
            // 3 quadrant
            else if ((tmpLat2 < 0 && tmpLong2 < 0))
            {
                deg = 180 - deg;
            }
            // 4 quadrant
            else if ((tmpLat2 > 0 && tmpLong2 < 0))
            {
                //deg = deg;
            }

            tmpWAP1.X = 0;
            tmpWAP1.Y = 0;
            tmpWAP1.Distance = beacon1.Distance;
            tmpWAP2 = myRotationForBeacon(tmpLat2, tmpLong2, beacon2.Distance, deg);
            tmpWAP3 = myRotationForBeacon(tmpLat3, tmpLong3, beacon3.Distance, deg);

            MyLat = (Math.Pow(tmpWAP1.Distance, 2) - Math.Pow(tmpWAP2.Distance, 2) + Math.Pow(tmpWAP2.X, 2)) / (2 * tmpWAP2.X);

            MyLong = (Math.Pow(tmpWAP1.Distance, 2) - Math.Pow(tmpWAP3.Distance, 2) - Math.Pow(MyLat, 2)
                            + Math.Pow(MyLat - tmpWAP3.X, 2) + Math.Pow(tmpWAP3.Y, 2)) / (2 * tmpWAP3.Y);

            var MyLocation = myRotation(MyLat, MyLong, 0, -deg);

            MyPosition.X = (long)(MyLocation[0] + beacon1.X);
            MyPosition.Y = (long)(MyLocation[1] + beacon1.Y);

            return MyPosition;
        }
예제 #4
0
        public Position Trilaterate(iBeacon beacon1, iBeacon beacon2, iBeacon beacon3)
        {
            //Dessa tre används för att förenkla beräkningen
            var tmpWAP1 = new iBeacon();
            var tmpWAP2 = new iBeacon();
            var tmpWAP3 = new iBeacon();

            double tmpLat2, tmpLong2, tmpLat3, tmpLong3;
            double tmpSlide, deg;
            double MyLat, MyLong;

            var MyPosition = new Position();

            //Utgå från att Lat1 är origo
            tmpLat2  = beacon2.X - beacon1.X;
            tmpLong2 = beacon2.Y - beacon1.Y;
            tmpLat3  = beacon3.X - beacon1.X;
            tmpLong3 = beacon3.Y - beacon1.Y;

            tmpSlide = Math.Sqrt(Math.Pow(tmpLat2, 2) + Math.Pow(tmpLong2, 2));

            //deg = (180/Math.PI)*Math.acos( ((Math.Pow(tmpLat2,2) + Math.Pow(tmpSlide,2) - Math.Pow(tmpLong2, 2)) / (2*tmpLat2*tmpSlide)) );
            deg = (180 / Math.PI) * Math.Acos(Math.Abs(tmpLat2) / Math.Abs(tmpSlide));

            // 1 quadrant
            if ((tmpLat2 > 0 && tmpLong2 > 0))
            {
                deg = 360 - deg;
            }
            else if ((tmpLat2 < 0 && tmpLong2 > 0))
            {
                deg = 180 + deg;
            }
            // 3 quadrant
            else if ((tmpLat2 < 0 && tmpLong2 < 0))
            {
                deg = 180 - deg;
            }
            // 4 quadrant
            else if ((tmpLat2 > 0 && tmpLong2 < 0))
            {
                //deg = deg;
            }

            tmpWAP1.X        = 0;
            tmpWAP1.Y        = 0;
            tmpWAP1.Distance = beacon1.Distance;
            tmpWAP2          = myRotationForBeacon(tmpLat2, tmpLong2, beacon2.Distance, deg);
            tmpWAP3          = myRotationForBeacon(tmpLat3, tmpLong3, beacon3.Distance, deg);


            MyLat = (Math.Pow(tmpWAP1.Distance, 2) - Math.Pow(tmpWAP2.Distance, 2) + Math.Pow(tmpWAP2.X, 2)) / (2 * tmpWAP2.X);

            MyLong = (Math.Pow(tmpWAP1.Distance, 2) - Math.Pow(tmpWAP3.Distance, 2) - Math.Pow(MyLat, 2)
                      + Math.Pow(MyLat - tmpWAP3.X, 2) + Math.Pow(tmpWAP3.Y, 2)) / (2 * tmpWAP3.Y);

            var MyLocation = myRotation(MyLat, MyLong, 0, -deg);

            MyPosition.X = (long)(MyLocation[0] + beacon1.X);
            MyPosition.Y = (long)(MyLocation[1] + beacon1.Y);

            return(MyPosition);
        }