Exemple #1
0
        public bool CheckCollision(Robot robot, SegmentsIntersector segmentsIntersector)
        {
            Line firstLine  = robot.GetLines()[0];
            Line secondLine = robot.GetLines()[1];
            bool sentinel   = false;

            foreach (var extendedRectangle in Colliders)
            {
                foreach (var line in extendedRectangle.GetLines())
                {
                    bool intersectionWithFirst  = segmentsIntersector.Intersect(firstLine, line);
                    bool intersectionWithSecond = segmentsIntersector.Intersect(secondLine, line);

                    if (intersectionWithFirst || intersectionWithSecond)
                    {
                        sentinel = true;
                        break;
                    }
                }
                if (sentinel)
                {
                    break;
                }
            }
            if (sentinel)
            {
                return(true);
            }
            return(false);
        }
Exemple #2
0
        public bool CheckCollision(Robot robot, SegmentsIntersector segmentsIntersector)
        {
            Line firstLine = robot.GetLines()[0];
            Line secondLine = robot.GetLines()[1];
            bool sentinel = false;
            foreach (var extendedRectangle in Colliders)
            {
                foreach (var line in extendedRectangle.GetLines())
                {
                    bool intersectionWithFirst = segmentsIntersector.Intersect(firstLine, line);
                    bool intersectionWithSecond = segmentsIntersector.Intersect(secondLine, line);

                    if (intersectionWithFirst || intersectionWithSecond)
                    {
                        sentinel = true;
                        break;
                    }
                }
                if (sentinel)
                {
                    break;
                }
            }
            if (sentinel)
            {
                return true;
            }
            return false;
        }
Exemple #3
0
        public void GenerateAnglesArray(Robot robot, Canvas Canvas, SegmentsIntersector segmentsIntersector)
        {
            int positiveCounter = 0;

            for (int i = 0; i < maxAngle; i++)
            {
                for (int j = 0; j < maxAngle; j++)
                {
                    robot.UpdateAngles(i, j);
                    robot.Reset(Canvas);
                    Line firstLine  = robot.GetLines()[0];
                    Line secondLine = robot.GetLines()[1];
                    bool sentinel   = false;
                    foreach (var extendedRectangle in Colliders)
                    {
                        foreach (var line in extendedRectangle.GetLines())
                        {
                            bool intersectionWithFirst  = segmentsIntersector.Intersect(firstLine, line);
                            bool intersectionWithSecond = segmentsIntersector.Intersect(secondLine, line);

                            if (intersectionWithFirst || intersectionWithSecond)
                            {
                                sentinel = true;
                                break;
                            }
                        }
                        if (sentinel)
                        {
                            break;
                        }
                    }
                    if (sentinel)
                    {
                        anglesArray[i, j] = false;
                    }
                    else
                    {
                        anglesArray[i, j] = true;
                        positiveCounter++;
                        if (i % 4 == 0 && j % 2 == 0)
                        {
                            //firstLine.Stroke = new SolidColorBrush() {Color = Color.FromArgb(50, 0, 255, 0)};
                            secondLine.Stroke = new SolidColorBrush()
                            {
                                Color = Color.FromArgb(50, 0, 0, 200)
                            };
                            //lineContainer.Add(firstLine);
                            secondLine.X1 = secondLine.X2 - 1;
                            secondLine.Y1 = secondLine.Y2 - 1;
                            lineContainer.Add(secondLine);
                            Canvas.Children.Add(secondLine);
                        }
                    }
                }
            }
            int d = 10;
        }
Exemple #4
0
        private void CheckIntersections()
        {
            Line l1 = new Line();

            l1.StrokeThickness = 3;
            l1.Stroke          = Brushes.Blue;
            l1.X1 = 20;
            l1.Y1 = 20;
            l1.X2 = 300;
            l1.Y2 = 350;

            Line l2 = new Line();

            l2.X1 = 20;
            l2.Y1 = 0;
            l2.X2 = 0;
            l2.Y2 = 20;

            //Canvas.Children.Add(l1);

            if (colliderContainer == null)
            {
                return;
            }

            foreach (var extendedRectangle in colliderContainer.Colliders)
            {
                foreach (var line in extendedRectangle.GetLines())
                {
                    bool res = segmentsIntersector.Intersect(l1, line);
                    if (res)
                    {
                        Line l = new Line();
                        l.StrokeThickness = 3;
                        l.Stroke          = Brushes.Red;
                        l.X1 = line.X1;
                        l.Y1 = line.Y1;
                        l.X2 = line.X2;
                        l.Y2 = line.Y2;
                        dragCanvas.Children.Add(l);
                    }
                }
            }
        }
Exemple #5
0
        public void GenerateAnglesArray(Robot robot, Canvas Canvas, SegmentsIntersector segmentsIntersector)
        {
            int positiveCounter = 0;
            for (int i = 0; i < maxAngle; i++)
                for (int j = 0; j < maxAngle; j++)
                {
                    robot.UpdateAngles(i, j);
                    robot.Reset(Canvas);
                    Line firstLine = robot.GetLines()[0];
                    Line secondLine = robot.GetLines()[1];
                    bool sentinel = false;
                    foreach (var extendedRectangle in Colliders)
                    {
                        foreach (var line in extendedRectangle.GetLines())
                        {
                            bool intersectionWithFirst = segmentsIntersector.Intersect(firstLine, line);
                            bool intersectionWithSecond = segmentsIntersector.Intersect(secondLine, line);

                            if (intersectionWithFirst || intersectionWithSecond)
                            {
                                sentinel = true;
                                break;
                            }
                        }
                        if (sentinel)
                        {
                            break;
                        }
                    }
                    if (sentinel)
                    {
                        anglesArray[i, j] = false;
                    }
                    else
                    {
                        anglesArray[i, j] = true;
                        positiveCounter++;
                        if (i%4 == 0 && j % 2 == 0)
                        {
                            //firstLine.Stroke = new SolidColorBrush() {Color = Color.FromArgb(50, 0, 255, 0)};
                            secondLine.Stroke = new SolidColorBrush() {Color = Color.FromArgb(50, 0, 0, 200)};
                            //lineContainer.Add(firstLine);
                            secondLine.X1 = secondLine.X2 - 1;
                            secondLine.Y1 = secondLine.Y2 - 1;
                            lineContainer.Add(secondLine);
                            Canvas.Children.Add(secondLine);
                        }
                    }
                }
            int d = 10;
        }