Beispiel #1
0
        private void findPotentialPointsForAnchor(ConvexHullNodes anchor)
        {
            Point dest = new Point(anchor.node.CenterLocation.X, 10); // x-axis

            foreach (Sensor entry in anchor.node.NeighborsTable)
            {
                foreach (Sensor x in SetofNodes)
                {
                    if (ConvexNodes.Count > 3 && x == PointZero)
                    {
                        ConvexHullNodes nei = new ConvexHullNodes(x, 0);
                        anchor.PotentialNextHop.Add(nei);
                        return;
                    }
                    if (x.ID == entry.ID && !ConvexNodes.Contains(x))
                    {
                        double          angle = Operations.GetDirectionAngle(anchor.node.CenterLocation, dest, x.CenterLocation);
                        ConvexHullNodes nei   = new ConvexHullNodes(x, angle);
                        anchor.PotentialNextHop.Add(nei);
                        //anchor.PotentialNextHop.Add(x);
                    }
                }
            }
            SubsetOfHull.Push(anchor);
        }
Beispiel #2
0
        private void startBuilding()
        {
            bool takeNextPoint = true;

            SubsetOfHull.Push(SortedSetOfConvexNodes.Dequeue());
            do
            {
                if (takeNextPoint)
                {
                    SubsetOfHull.Push(SortedSetOfConvexNodes.Dequeue());
                }

                ConvexHullNodes PointThree = SubsetOfHull.Pop();
                ConvexHullNodes PointTwo   = SubsetOfHull.Pop();
                ConvexHullNodes PointOne   = SubsetOfHull.Pop();



                if (isClockwise(PointOne, PointTwo, PointThree))
                {
                    SubsetOfHull.Push(PointOne);
                    SubsetOfHull.Push(PointTwo);
                    SubsetOfHull.Push(PointThree);
                    takeNextPoint = true;
                }
                else
                {
                    SubsetOfHull.Push(PointOne);
                    SubsetOfHull.Push(PointThree);
                    if (SubsetOfHull.Count >= 3)
                    {
                        takeNextPoint = false;
                    }
                }
            } while (SortedSetOfConvexNodes.Count > 0);

            // Console.WriteLine("Ending ****");
            int c = SubsetOfHull.Count;

            do
            {
                ConvexHullNodes x = SubsetOfHull.Pop();
                ConvexNodes.Add(x.node);
                //   x.node.ShowComunicationRange(true);
                //  Console.WriteLine(x.node.ID);
            } while (SubsetOfHull.Count > 0);

            RingNodesFunctions.doLastCheck();
        }
Beispiel #3
0
        private ConvexHullNodes getLowestAngle(List <ConvexHullNodes> set)
        {
            double          lowest = 10;
            ConvexHullNodes holder = null;

            foreach (ConvexHullNodes compare in set)
            {
                if (compare.polarAngle < lowest)
                {
                    lowest = compare.polarAngle;
                    holder = compare;
                }
            }

            return(holder);
        }
Beispiel #4
0
        private void getPolarAngleToPointsFromAnchor(Sensor anchor)
        {
            // according to the direction they make with P0 and the X-Axis
            Point dest = new Point(anchor.CenterLocation.X + InitialRadius + ThreshHold, anchor.CenterLocation.Y); // x-axis

            foreach (Sensor px in SetofNodes)
            {
                if (px.ID != anchor.ID)
                {
                    double          angle = Operations.GetDirectionAngle(anchor.CenterLocation, dest, px.CenterLocation);
                    ConvexHullNodes node  = new ConvexHullNodes(px, angle);
                    ConvexHullSet.Add(node);
                    //Console.WriteLine("Node {0} , has Angle {1}", node.node.ID, node.polarAngle);
                    // Console.WriteLine("Node {0} , has Angle {1}", px.ID, angle);
                }
            }
        }
Beispiel #5
0
        private bool isClockwise(ConvexHullNodes one, ConvexHullNodes two, ConvexHullNodes three)
        {
            Point a = one.node.CenterLocation;
            Point b = two.node.CenterLocation;
            Point c = three.node.CenterLocation;

            double value = ((b.X - a.X) * (c.Y - a.Y) - (c.X - a.X) * (b.Y - a.Y));

            if (value >= 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #6
0
        private static void ConvexHullBuildMethod()
        {
            Ring constructor = new Ring();

            // showVirtualRadius();
            constructor.findTheSetofNodes();
            constructor.findPointZero();
            constructor.getPolarAngleToPointsFromAnchor(PointZero);
            ConvexHullNodes AnchorPoint = new ConvexHullNodes(PointZero, 0);

            AnchorPoint.PotentialNextHop = ConvexHullSet;
            PointZeroConvex = AnchorPoint;
            constructor.sortConvexHullSet(PointZero);
            SubsetOfHull.Push(AnchorPoint);
            constructor.startBuilding();
            constructor.drawVirtualLine();
            //constructor.startFromPointZero();
        }
Beispiel #7
0
        private void sortConvexHullSet(Sensor anchor)
        {
            List <ConvexHullNodes> beforeSort = ConvexHullSet;
            ConvexHullNodes        small      = null;

            do
            {
                try
                {
                    small = getLowestAngle(beforeSort);
                    SortedSetOfConvexNodes.Enqueue(small);
                    beforeSort.Remove(small);
                    // Console.WriteLine("Node {0} has angle {1}", small.node.ID, small.polarAngle);
                }
                catch
                {
                    small = null;
                    MessageBox.Show("Just returned a null");
                }
            } while (beforeSort.Count > 0);
        }
Beispiel #8
0
        private void sortMyPotentialNextHop(ConvexHullNodes from)
        {
            List <ConvexHullNodes> beforeSort = from.PotentialNextHop;

            ConvexHullNodes small = null;

            do
            {
                try
                {
                    small = getLowestAngle(beforeSort);
                    from.SortedConvexHullSet.Enqueue(small);
                    beforeSort.Remove(small);
                    //  Console.WriteLine("Node {0} has angle {1}", small.node.ID, small.polarAngle);
                }
                catch
                {
                    small = null;
                    MessageBox.Show("Just returned a null");
                }
            } while (beforeSort.Count > 0);
        }