/// <summary>
        /// Calculates the position
        /// </summary>
        /// <param name="BlindNode">The BlindNode to be positioned</param>
        /// <param name="filterMethod">The filter to use on the RSS values</param>
        /// <param name="RangingMethod">The ranging method</param>
        /// <param name="multihop">use multihop or not</param>
        /// <returns>The position of the blind node</returns>
        public static Point CalculatePosition(Node BlindNode, Node.FilterMethod filterMethod, Node.RangingMethod rangingMethod, bool multihop)
        {
            List<Point> intersectionPoints = new List<Point>();
            List<AnchorNode> AllAnchors = new List<AnchorNode>();
            List<IntersectedAnchors> anchors = new List<IntersectedAnchors>();
            IntersectedAnchors anchor = new IntersectedAnchors();
            List<int> CountOfCircles = new List<int>();

            Point center = new Point();
            int numberOfCircles = 0;

            foreach (AnchorNode AN in BlindNode.Anchors)
            {
                AN.fRSS = filterMethod(AN.RSS);
                AN.range = rangingMethod(AN.fRSS);
            }
            foreach (AnchorNode VAN in BlindNode.VirtualAnchors)
            {
                VAN.fRSS = filterMethod(VAN.RSS);
                VAN.range = rangingMethod(VAN.fRSS);
            }

                if (!multihop)
                {
                    if (BlindNode.Anchors.Count >= 3)
                    {

                        for (int i = 0; i < BlindNode.Anchors.Count - 1; i++)
                        {
                            for (int j = i + 1; j < BlindNode.Anchors.Count; j++)
                            {
                                List<Point> crossingPoints = GeometryHelper.Intersect(BlindNode.Anchors[i].posx, BlindNode.Anchors[i].posy, BlindNode.Anchors[i].range, BlindNode.Anchors[j].posx, BlindNode.Anchors[j].posy, BlindNode.Anchors[j].range);
                                if (crossingPoints != null)
                                {
                                    foreach (Point crossing in crossingPoints)
                                        intersectionPoints.Add(crossing);

                                }
                            }
                        }
                        if (intersectionPoints.Count >= 3)
                            center = Cluster(intersectionPoints, BlindNode.Anchors.Count);
                        else
                        {
                            center = null;
                        }
                    }
                    else
                        center = null;

                }
                else
                {
                    for (int i = 0; i < BlindNode.Anchors.Count - 1; i++)
                    {
                        for (int j = i + 1; j < BlindNode.Anchors.Count; j++)
                        {
                            List<Point> crossingPoints = GeometryHelper.Intersect(BlindNode.Anchors[i].posx, BlindNode.Anchors[i].posy, BlindNode.Anchors[i].range, BlindNode.Anchors[j].posx, BlindNode.Anchors[j].posy, BlindNode.Anchors[j].range);
                            if (crossingPoints != null)
                            {
                                foreach (Point crossing in crossingPoints)
                                    intersectionPoints.Add(crossing);

                            }
                        }
                    }
                    if (intersectionPoints.Count < 3)
                    {
                        intersectionPoints.Clear();

                        foreach (AnchorNode an in BlindNode.Anchors)
                            AllAnchors.Add(an);
                        foreach (AnchorNode van in BlindNode.VirtualAnchors)
                            AllAnchors.Add(van);

                        for (int i = 0; i < AllAnchors.Count - 1; i++)
                        {
                            for (int j = i + 1; j < AllAnchors.Count; j++)
                            {
                                List<Point> crossingPoints = GeometryHelper.Intersect(AllAnchors[i].posx, AllAnchors[i].posy, AllAnchors[i].range, AllAnchors[j].posx, AllAnchors[j].posy, AllAnchors[j].range);
                                if (crossingPoints != null)
                                {
                                    foreach (Point crossing in crossingPoints)
                                        intersectionPoints.Add(crossing);

                                }
                            }
                        }
                        for (int i = 0; i < AllAnchors.Count; i++)
                        {
                            numberOfCircles = 0;
                            for (int j = 0; j < AllAnchors.Count; j++)
                            {
                                
                                if (GeometryHelper.BelongTo(AllAnchors[i].posx, AllAnchors[i].posy, AllAnchors[i].range, AllAnchors[j].posx, AllAnchors[j].posy, AllAnchors[j].range))
                                    numberOfCircles++;
                            }
                            CountOfCircles.Add(numberOfCircles);
                        }
                        List<int> anchorss = CountOfCircles.FindAll(number => number == 1);

                        if (intersectionPoints.Count >= 3)
                            center = Cluster(intersectionPoints, (AllAnchors.Count - anchorss.Count) );
                        else
                        {
                            center = null;
                        }

                    }
                    else
                        center = Cluster(intersectionPoints, BlindNode.Anchors.Count);

                }
                return center;
        }
Пример #2
0
        /// <summary>
        /// Calculates the position
        /// </summary>
        /// <param name="BlindNode">The BlindNode to be positioned</param>
        /// <param name="filterMethod">The filter to use on the RSS values</param>
        /// <param name="RangingMethod">The ranging method</param>
        /// <param name="multihop">use multihop or not</param>
        /// <returns>The position of the blind node</returns>
        public static Point CalculatePosition(Node BlindNode, Node.FilterMethod filterMethod, Node.RangingMethod rangingMethod, bool multihop)
        {
            List <Point>              intersectionPoints = new List <Point>();
            List <AnchorNode>         AllAnchors         = new List <AnchorNode>();
            List <IntersectedAnchors> anchors            = new List <IntersectedAnchors>();
            IntersectedAnchors        anchor             = new IntersectedAnchors();
            List <int> CountOfCircles = new List <int>();

            Point center          = new Point();
            int   numberOfCircles = 0;

            foreach (AnchorNode AN in BlindNode.Anchors)
            {
                AN.fRSS  = filterMethod(AN.RSS);
                AN.range = rangingMethod(AN.fRSS);
            }
            foreach (AnchorNode VAN in BlindNode.VirtualAnchors)
            {
                VAN.fRSS  = filterMethod(VAN.RSS);
                VAN.range = rangingMethod(VAN.fRSS);
            }

            if (!multihop)
            {
                if (BlindNode.Anchors.Count >= 3)
                {
                    for (int i = 0; i < BlindNode.Anchors.Count - 1; i++)
                    {
                        for (int j = i + 1; j < BlindNode.Anchors.Count; j++)
                        {
                            List <Point> crossingPoints = GeometryHelper.Intersect(BlindNode.Anchors[i].posx, BlindNode.Anchors[i].posy, BlindNode.Anchors[i].range, BlindNode.Anchors[j].posx, BlindNode.Anchors[j].posy, BlindNode.Anchors[j].range);
                            if (crossingPoints != null)
                            {
                                foreach (Point crossing in crossingPoints)
                                {
                                    intersectionPoints.Add(crossing);
                                }
                            }
                        }
                    }
                    if (intersectionPoints.Count >= 3)
                    {
                        center = Cluster(intersectionPoints, BlindNode.Anchors.Count);
                    }
                    else
                    {
                        center = null;
                    }
                }
                else
                {
                    center = null;
                }
            }
            else
            {
                for (int i = 0; i < BlindNode.Anchors.Count - 1; i++)
                {
                    for (int j = i + 1; j < BlindNode.Anchors.Count; j++)
                    {
                        List <Point> crossingPoints = GeometryHelper.Intersect(BlindNode.Anchors[i].posx, BlindNode.Anchors[i].posy, BlindNode.Anchors[i].range, BlindNode.Anchors[j].posx, BlindNode.Anchors[j].posy, BlindNode.Anchors[j].range);
                        if (crossingPoints != null)
                        {
                            foreach (Point crossing in crossingPoints)
                            {
                                intersectionPoints.Add(crossing);
                            }
                        }
                    }
                }
                if (intersectionPoints.Count < 3)
                {
                    intersectionPoints.Clear();

                    foreach (AnchorNode an in BlindNode.Anchors)
                    {
                        AllAnchors.Add(an);
                    }
                    foreach (AnchorNode van in BlindNode.VirtualAnchors)
                    {
                        AllAnchors.Add(van);
                    }

                    for (int i = 0; i < AllAnchors.Count - 1; i++)
                    {
                        for (int j = i + 1; j < AllAnchors.Count; j++)
                        {
                            List <Point> crossingPoints = GeometryHelper.Intersect(AllAnchors[i].posx, AllAnchors[i].posy, AllAnchors[i].range, AllAnchors[j].posx, AllAnchors[j].posy, AllAnchors[j].range);
                            if (crossingPoints != null)
                            {
                                foreach (Point crossing in crossingPoints)
                                {
                                    intersectionPoints.Add(crossing);
                                }
                            }
                        }
                    }
                    for (int i = 0; i < AllAnchors.Count; i++)
                    {
                        numberOfCircles = 0;
                        for (int j = 0; j < AllAnchors.Count; j++)
                        {
                            if (GeometryHelper.BelongTo(AllAnchors[i].posx, AllAnchors[i].posy, AllAnchors[i].range, AllAnchors[j].posx, AllAnchors[j].posy, AllAnchors[j].range))
                            {
                                numberOfCircles++;
                            }
                        }
                        CountOfCircles.Add(numberOfCircles);
                    }
                    List <int> anchorss = CountOfCircles.FindAll(number => number == 1);

                    if (intersectionPoints.Count >= 3)
                    {
                        center = Cluster(intersectionPoints, (AllAnchors.Count - anchorss.Count));
                    }
                    else
                    {
                        center = null;
                    }
                }
                else
                {
                    center = Cluster(intersectionPoints, BlindNode.Anchors.Count);
                }
            }
            return(center);
        }