예제 #1
0
        public MapScreen()
        {
            Initialized += MapScreen_Initialized;
            Loaded      += MapScreen_Loaded;

            InitializeComponent();

            DataContext = this;

            /* Set gateways of the environment */
            try
            {
                List <Gateway> gateways = IndoorPositioningClient.GetGateways();
                environmentShape.Gateways = gateways.ToArray();
            }
            catch (Exception ex) { MessageBox.Show(ex.ToString()); }
        }
예제 #2
0
 private void Load()
 {
     try
     {
         Mouse.OverrideCursor    = Cursors.Wait;
         lstGateways.ItemsSource = IndoorPositioningClient.GetGateways();
         if (lstGateways.Items.Count > 0)
         {
             lstGateways.SelectedIndex = selectedIndex;
         }
         Mouse.OverrideCursor = Cursors.Arrow;
     }
     catch (Exception ex)
     {
         Mouse.OverrideCursor = Cursors.Arrow;
         MessageBox.Show(ex.ToString());
     }
 }
예제 #3
0
        private Coordinate Positioning_Proximity()
        {
            List <Gateway> gateways = IndoorPositioningClient.GetGateways();

            /* get the Rssi values of the beacon in question from the server */
            RssiValue[] rssiValues = IndoorPositioningClient.GetRssi(gateways.Count);

            CoordinateAndDistance[] cooDist = new CoordinateAndDistance[gateways.Count];
            for (int i = 0; i < gateways.Count; i++)
            {
                cooDist[i] = new CoordinateAndDistance()
                {
                    coordinate = new Coordinate()
                    {
                        Xaxis = (int)GetGatewayXaxis(gateways[i]),
                        Yaxis = (int)GetGatewayYaxis(gateways[i]),
                    },
                    dist = rssiValues[i].Rssi
                };
            }

            Coordinate coordinateFirstAndSecondLine = new Coordinate();
            Coordinate coordinateFirstAndThirdLine  = new Coordinate();
            Coordinate coordinateSecondAndThirdLine = new Coordinate();

            /* Create a vector from the coordinates */
            /* Measure the first point of crossing the first and second line*/
            DoubleMatrix matrixFirstAndSecondLine = new DoubleMatrix(new double[, ]
            {
                {
                    cooDist[0].coordinate.Xaxis - cooDist[1].coordinate.Xaxis,
                    cooDist[0].coordinate.Yaxis - cooDist[1].coordinate.Yaxis
                },
                {
                    cooDist[0].coordinate.Xaxis - cooDist[2].coordinate.Xaxis,
                    cooDist[0].coordinate.Yaxis - cooDist[2].coordinate.Yaxis
                }
            });

            /* If the determinant value of the matrix is 0, it means this matrix cannot be inverted.
             * We can have the exact point values with one of the reference points. */
            if (NMathFunctions.Determinant(matrixFirstAndSecondLine) == 0)
            {
                return(cooDist[0].coordinate);
            }

            //matrixFirstAndSecondLine = matrixFirstAndSecondLine.Transform((p) => p * 2);
            DoubleMatrix inversedMatrixFirstAndSecondLine = NMathFunctions.Inverse(matrixFirstAndSecondLine);
            DoubleVector vectorFirstAndSecondLine         = new DoubleVector(new double[]
            {
                cooDist[0].coordinate.GetNormPow() - cooDist[1].coordinate.GetNormPow() - cooDist[0].GetDistPow() + cooDist[1].GetDistPow(),
                cooDist[0].coordinate.GetNormPow() - cooDist[2].coordinate.GetNormPow() - cooDist[0].GetDistPow() + cooDist[2].GetDistPow()
            });

            vectorFirstAndSecondLine = vectorFirstAndSecondLine.Transform((p) => p / 2);

            DoubleVector coordinateVectorFirstAndSecondLine = NMathFunctions.Product(inversedMatrixFirstAndSecondLine,
                                                                                     vectorFirstAndSecondLine);

            coordinateFirstAndSecondLine.Xaxis = (int)coordinateVectorFirstAndSecondLine[0];
            coordinateFirstAndSecondLine.Yaxis = (int)coordinateVectorFirstAndSecondLine[1];

            /* Measure the first point of crossing the first and third line*/
            DoubleMatrix matrixFirstAndThirdLine = new DoubleMatrix(new double[, ]
            {
                {
                    cooDist[0].coordinate.Xaxis - cooDist[1].coordinate.Xaxis,
                    cooDist[0].coordinate.Yaxis - cooDist[1].coordinate.Yaxis
                },
                {
                    cooDist[1].coordinate.Xaxis - cooDist[2].coordinate.Xaxis,
                    cooDist[1].coordinate.Yaxis - cooDist[2].coordinate.Yaxis
                }
            });

            /* If the determinant value of the matrix is 0, it means this matrix cannot be inverted.
             * We can have the exact point values with one of the reference points. */
            if (NMathFunctions.Determinant(matrixFirstAndThirdLine) == 0)
            {
                return(cooDist[0].coordinate);
            }

            //matrixFirstAndThirdLine = matrixFirstAndThirdLine.Transform((p) => p * 2);
            DoubleMatrix inversedMatrixFirstAndThirdLine = NMathFunctions.Inverse(matrixFirstAndThirdLine);
            DoubleVector vectorFirstAndThirdLine         = new DoubleVector(new double[]
            {
                cooDist[0].coordinate.GetNormPow() - cooDist[1].coordinate.GetNormPow() - cooDist[0].GetDistPow() + cooDist[1].GetDistPow(),
                cooDist[1].coordinate.GetNormPow() - cooDist[2].coordinate.GetNormPow() - cooDist[1].GetDistPow() + cooDist[2].GetDistPow()
            });

            vectorFirstAndThirdLine = vectorFirstAndThirdLine.Transform((p) => p / 2);

            DoubleVector coordinateVectorFirstAndThirdLine = NMathFunctions.Product(inversedMatrixFirstAndThirdLine,
                                                                                    vectorFirstAndThirdLine);

            coordinateFirstAndThirdLine.Xaxis = (int)coordinateVectorFirstAndThirdLine[0];
            coordinateFirstAndThirdLine.Yaxis = (int)coordinateVectorFirstAndThirdLine[1];

            /* Measure the first point of crossing the first and third line*/
            DoubleMatrix matrixSecondAndThirdLine = new DoubleMatrix(new double[, ]
            {
                {
                    cooDist[0].coordinate.Xaxis - cooDist[2].coordinate.Xaxis,
                    cooDist[0].coordinate.Yaxis - cooDist[2].coordinate.Yaxis
                },
                {
                    cooDist[1].coordinate.Xaxis - cooDist[2].coordinate.Xaxis,
                    cooDist[1].coordinate.Yaxis - cooDist[2].coordinate.Yaxis
                }
            });

            /* If the determinant value of the matrix is 0, it means this matrix cannot be inverted.
             * We can have the exact point values with one of the reference points. */
            if (NMathFunctions.Determinant(matrixSecondAndThirdLine) == 0)
            {
                return(cooDist[0].coordinate);
            }

            //matrixSecondAndThirdLine = matrixSecondAndThirdLine.Transform((p) => p * 2);
            DoubleMatrix inversedMatrixSecondAndThirdLine = NMathFunctions.Inverse(matrixSecondAndThirdLine);
            DoubleVector vectorSecondAndThirdLine         = new DoubleVector(new double[]
            {
                cooDist[0].coordinate.GetNormPow() - cooDist[2].coordinate.GetNormPow() - cooDist[0].GetDistPow() + cooDist[2].GetDistPow(),
                cooDist[1].coordinate.GetNormPow() - cooDist[2].coordinate.GetNormPow() - cooDist[1].GetDistPow() + cooDist[2].GetDistPow()
            });

            vectorSecondAndThirdLine = vectorSecondAndThirdLine.Transform((p) => p / 2);

            DoubleVector coordinateVectorSecondAndThirdLine = NMathFunctions.Product(inversedMatrixSecondAndThirdLine,
                                                                                     vectorSecondAndThirdLine);

            coordinateSecondAndThirdLine.Xaxis = (int)coordinateVectorSecondAndThirdLine[0];
            coordinateSecondAndThirdLine.Yaxis = (int)coordinateVectorSecondAndThirdLine[1];

            int xaxis =
                (coordinateFirstAndSecondLine.Xaxis +
                 coordinateFirstAndThirdLine.Xaxis +
                 coordinateSecondAndThirdLine.Xaxis) / 3;
            int yaxis =
                (coordinateFirstAndSecondLine.Yaxis +
                 coordinateFirstAndThirdLine.Yaxis +
                 coordinateSecondAndThirdLine.Yaxis) / 3;

            Debug.WriteLine("Xaxis:" + xaxis);
            Debug.WriteLine("Yaxis:" + yaxis);

            return(new Coordinate()
            {
                Xaxis = xaxis,
                Yaxis = yaxis
            });
        }