private bool IsWater(Point p)
        {
            p = new Point(2 * (p.x / bounds.width - 0.5), 2 * (p.y / bounds.height - 0.5));
            double angle  = Math.Atan2(p.y, p.x);
            double length = 0.5 * (Math.Max(Math.Abs(p.x), Math.Abs(p.y)) + p.Length());
            double r1     = 0.5 + 0.40 * Math.Sin(startAngle + bumps * angle + Math.Cos((bumps + 3) * angle));
            double r2     = 0.7 - 0.20 * Math.Sin(startAngle + bumps * angle - Math.Cos((bumps + 2) * angle));

            if (Math.Abs(angle - dipAngle) < dipWidth ||
                Math.Abs(angle - dipAngle + 2 * Math.PI) < dipWidth ||
                Math.Abs(angle - dipAngle - 2 * Math.PI) < dipWidth)
            {
                r1 = 0.2;
                r2 = 0.2;
            }

            return(!(length < r1 || (length > r1 * ISLAND_FACTOR && length < r2)));
        }
        public FiniteElementNode GetNodeOnPoint(Point point)
        {
            FiniteElementNode node = null;

            if (Nodes.Count > 0)
            {
                node = Nodes[0];
                double minDistance = Point.Length(point, node.Point);
                foreach (FiniteElementNode finiteElementNode in Nodes)
                {
                    double distance = Point.Length(point, finiteElementNode.Point);
                    if (distance < minDistance)
                    {
                        minDistance = distance;
                        node        = finiteElementNode;
                    }
                }
            }
            return(node);
        }
        public static void DrawCircle(Point p1, Point p2, int position, bool fill)
        {
            int    left      = Console.CursorLeft;
            int    top       = Console.CursorTop;
            double r         = Point.Length(p1, p2);
            int    leftSide  = (int)Math.Round(p1.X - r);
            int    rightSide = (int)Math.Round(p1.X + r);
            int    upSide    = (int)Math.Round(p1.Y - r);
            int    downSide  = (int)Math.Round(p1.Y + r);

            for (int i = upSide; i <= downSide; i++)
            {
                for (int j = leftSide; j <= rightSide; j++)
                {
                    if (fill)
                    {
                        if (r >= Point.Length(p1, new Point(j, i)))
                        {
                            if (i >= 0 && j >= 0)
                            {
                                Console.SetCursorPosition(DrawMenu.LeftPicture + j, DrawMenu.TopPicture + i);
                                Console.Write(position);
                            }
                        }
                    }
                    else
                    {
                        if ((r >= Math.Round(Point.Length(p1, new Point(j, i)))) && (r - 1 < Math.Round(Point.Length(p1, new Point(j, i)))))
                        {
                            if (i >= 0 && j >= 0)
                            {
                                Console.SetCursorPosition(DrawMenu.LeftPicture + j, DrawMenu.TopPicture + i);
                                Console.Write(position);
                            }
                        }
                    }
                }
            }
            Console.SetCursorPosition(left, top);
        }
Exemple #4
0
        public static void AttachTouchTapEvent(this FrameworkElement element, Action <Point> tapEvent)
        {
            Stylus.SetIsPressAndHoldEnabled(element, false);
            Stylus.SetIsTapFeedbackEnabled(element, false);
            element.PreviewTouchDown += (sender, ex) =>
            {
                if (tapTrace.ContainsKey(ex.TouchDevice.Id) == false)
                {
                    TapInfo info = new TapInfo();
                    info.Key       = ex.TouchDevice.Id;
                    info.Position  = ex.GetTouchPoint(Application.Current.MainWindow).Position;
                    info.Timestamp = ex.Timestamp;
                    tapTrace.Add(ex.TouchDevice.Id, info);
                }
            };

            element.PreviewTouchUp += (sender, ex) =>
            {
                if (tapTrace.ContainsKey(ex.TouchDevice.Id))
                {
                    TapInfo info = tapTrace[ex.TouchDevice.Id];
                    tapTrace.Remove(ex.TouchDevice.Id);
                    int timeStampDiff = (ex.Timestamp - info.Timestamp);
                    if (timeStampDiff < 400)//0.4 seconds
                    {
                        Point newPos = ex.GetTouchPoint(Application.Current.MainWindow).Position;
                        Point result = newPos.Sub(info.Position);


                        if (result.Length() < GestureConsts.Current.DoubleTapDistance)
                        {
                            tapEvent(info.Position);
                        }
                    }
                }
            };
        }
Exemple #5
0
        public void StartGhostMoving()
        {
            if (TargetPoint.IsEmpty)
                return;

            Point pv = new Point(TargetPoint.X - X, TargetPoint.Y - Y);
            Point target = TargetPoint;
            if (pv.Length() > 160)
            {
                pv.Normalize(160);
            }

            m_game.AddAction(new GhostMoveAction(this, new Point(X + pv.X, Y + pv.Y)));
        }
Exemple #6
0
 public static double Length(FiniteElementNode a, FiniteElementNode b)
 {
     return(Point.Length(a.Point, b.Point));
 }
Exemple #7
0
        public static Point Normalize(this Point point, int len)
        {
            double l = point.Length();

            return(new Point((int)(point.X * len / l), (int)(point.Y * len / l)));
        }
        /// <summary>
        /// Normalizes vector
        /// </summary>
        /// <returns>Normalized vector</returns>
        public static Point2d Normalize(this Point vec)
        {
            double len = 1.0 / vec.Length();

            return(new Point2d(vec.X * len, vec.Y * len));
        }
Exemple #9
0
    public static Point Normalize(ref Point p1)
    {
        double length = p1.Length();

        return new Point(p1.x / length, p1.y / length, p1.z / length);
    }
Exemple #10
0
    public static Point Normalize(ref Point p1)
    {
        double length = p1.Length();

        return(new Point(p1.x / length, p1.y / length, p1.z / length));
    }
Exemple #11
0
        /// <summary>
        /// Возвращает время заданного пути по конкретной области.
        /// </summary>
        /// <param name="WayBegin">Начальная точка</param>
        /// <param name="WayEnd">Конечная точка</param>
        /// <returns>Время</returns>
        private double WalkTime(Point WayBegin, Point WayEnd)
        {
            double leng = Point.Length(WayBegin, WayEnd);

            return(leng / Properties.CurSpeed);
        }
Exemple #12
0
 public static double Norm(Point a)
 {
     return a.Length();
 }
        public static Point Normalize(this Point point, int len)
        {
            double num = point.Length();

            return(new Point((int)((double)(point.X * len) / num), (int)((double)(point.Y * len) / num)));
        }
Exemple #14
0
 public static double Norm(Point a)
 {
     return(a.Length());
 }
Exemple #15
0
        /// <summary>
        /// Метод считает относительно Полигонов 2 Юнитов и их наборов Way коллизию, если находит, то возвращает индекс Way в котором врезается во второго Юнита.
        /// </summary>
        /// <param name="curUnit">Текущий Юнит</param>
        /// <param name="movingUnit">Другой Юнит</param>
        /// <param name="curUnitWays">"Пути" текущего Юнита</param>
        /// <param name="movingUnitWays">"Пути" другого Юнита</param>
        /// <returns>Индекс элемента "Пути" коллизии</returns>
        private int CheckWaysCollision(Unit curUnit, Unit movingUnit, List <Way> curUnitWays, List <Way> movingUnitWays)
        {
            var pointsCur    = new List <Point>(curUnit.Polygon.Points);
            var pointsMoving = new List <Point>(movingUnit.Polygon.Points);

            var curUnitSegments    = Polyline.PointsToSegments(curUnitWays.ConvertAll(x => x.WayPoint));
            var movingUnitSegments = Polyline.PointsToSegments(movingUnitWays.ConvertAll(x => x.WayPoint));

            // Цикл по всем отрезкам пути текущего Юнита
            for (int i = 0; i < curUnitSegments.Count; i++)
            {
                var curSegment = curUnitSegments[i];

                var curUnitVector = new Point(curSegment.End.X - curSegment.Begin.X,
                                              curSegment.End.Y - curSegment.Begin.Y);

                // Перенесем все отрезки полигона текущего и рассматриваемого Юнитов на вектора их путей
                var curUnitPolySegments     = Polyline.PointsToSegments(pointsCur);
                var curUnitPolyLastSegments = new List <Segment>();
                var curAnotherPolySegments  = new List <Segment>();
                foreach (var cursegment in curUnitSegments)
                {
                    curUnitPolyLastSegments.Add(new Segment(new Point(cursegment.Begin.X + curUnitVector.X, cursegment.Begin.Y + curUnitVector.Y), new Point(cursegment.End.X + curUnitVector.X, cursegment.End.Y + curUnitVector.Y)));
                    // Достраиваем боковые отрезки
                    curAnotherPolySegments.Add(new Segment(cursegment.Begin, new Point(cursegment.Begin.X + curUnitVector.X, cursegment.Begin.Y + curUnitVector.Y)));
                }
                curUnitPolySegments.AddRange(curUnitPolyLastSegments);
                curUnitPolySegments.AddRange(curAnotherPolySegments);

                // Цикл по всем отрезкам пути движемого Юнита
                for (int j = 0; j < movingUnitSegments.Count; j++)
                {
                    var movingUnitSegment = movingUnitSegments[j];


                    var movingUnitVector = new Point(movingUnitSegment.End.X - movingUnitSegment.Begin.X,
                                                     movingUnitSegment.End.Y - movingUnitSegment.Begin.Y);

                    // Перенесем все отрезки полигона текущего и рассматриваемого Юнитов на вектора их путей
                    var movingUnitPolySegments     = Polyline.PointsToSegments(pointsMoving);
                    var movingAnotherPolySegments  = new List <Segment>();
                    var movingUnitPolyLastSegments = new List <Segment>();
                    foreach (var movingsegment in movingUnitSegments)
                    {
                        movingUnitPolyLastSegments.Add(new Segment(new Point(movingsegment.Begin.X + movingUnitVector.X, movingsegment.Begin.Y + movingUnitVector.Y), new Point(movingsegment.End.X + movingUnitVector.X, movingsegment.End.Y + movingUnitVector.Y)));
                        // Достраиваем боковые отрезки
                        movingAnotherPolySegments.Add(new Segment(movingsegment.Begin, new Point(movingsegment.Begin.X + movingUnitVector.X, movingsegment.Begin.Y + movingUnitVector.Y)));
                    }
                    movingUnitPolySegments.AddRange(movingUnitPolyLastSegments);
                    movingUnitPolySegments.AddRange(movingAnotherPolySegments);

                    var intersections = new List <Point>();
                    // Для всех отрезков движемого и текущего Юнитов, а также отрезков переноса по пути ищем пересечения

                    int movingIntersect = -1, curIntersect = -1;
                    for (int index = 0; index < movingUnitPolySegments.Count; index++)
                    {
                        var movingSegment = movingUnitPolySegments[index];
                        // Нашли пересечение - Выйдем
                        if (intersections.Count > 0)
                        {
                            movingIntersect = index;
                            break;
                        }
                        for (int index1 = 0; index1 < curUnitPolySegments.Count; index1++)
                        {
                            var currentSegment = curUnitPolySegments[index1];
                            intersections.AddRange(Intersect.GetIntersection(currentSegment, movingSegment));
                            // Нашли пересечение - Выйдем
                            if (intersections.Count > 0)
                            {
                                movingIntersect = index;
                                curIntersect    = index1;
                                break;
                            }
                        }
                    }


                    var pathCurSegment      = new Segment(curUnitPolySegments[curIntersect].Begin, curUnitPolySegments[curIntersect].End);
                    var pathMovingSegment   = new Segment(movingUnitPolySegments[curIntersect].Begin, movingUnitPolySegments[curIntersect].End);
                    var pathCurVectorLen    = Point.Length(pathCurSegment.Begin, pathCurSegment.End);
                    var pathMovingVectorLen = Point.Length(pathMovingSegment.Begin, pathMovingSegment.End);

                    // Посчитаем время
                    var currentTime = pathCurVectorLen / curUnit.Properties.CurSpeed;
                    var movingTime  = pathMovingVectorLen / movingUnit.Properties.CurSpeed;

                    currentTime = currentTime < movingTime ? currentTime : movingTime;

                    // Получим точки на отрезке полигона по времени
                    var curTimedPoints = new List <Point>();
                    foreach (var segment in curAnotherPolySegments)
                    {
                        curTimedPoints.Add(segment.Position(currentTime, curUnitWays[i].Time));
                    }

                    var movingTimedPoints = new List <Point>();
                    foreach (var segment in movingAnotherPolySegments)
                    {
                        movingTimedPoints.Add(segment.Position(currentTime, movingUnitWays[i].Time));
                    }

                    // Создаем полигоны
                    ConvexPolygon curPolygon = new ConvexPolygon(curTimedPoints), movPolygon = new ConvexPolygon(movingTimedPoints);
                    intersections.Clear();
                    intersections.AddRange(Intersect.GetIntersection(curPolygon, movPolygon));

                    if (intersections.Count > 0 && currentTime > movingTime)
                    {
                        return(i);
                    }

                    // Применяем параллельно перенесенный полигон, как текущий набор точек дял движемого Юнита
                    pointsMoving = Polyline.SegmentsToPoints(movingUnitPolyLastSegments);
                }

                // Применяем параллельно перенесенный полигон, как текущий набор точек дял текущего Юнита
                pointsCur = Polyline.SegmentsToPoints(curUnitPolyLastSegments);
            }

            return(-1);
        }
Exemple #16
0
 public static Point ToUnitVector(this Point p)
 {
     return(p / p.Length());
 }
Exemple #17
0
        private void DrawPolygon(Point point)
        {
            if (!_started)
            {
                _started    = true;
                _lastVertex = new Vertex(1, point);
                _newPolygon = new Polygon(Color.MidnightBlue);
                _newPolygon.Vertices.Add(_lastVertex);
//                DrawDot(point, Color.Crimson);
                CommitDraw();
                return;
            }

            //Checking if it's time to end Cycle
            var firstVertex = _newPolygon.Vertices[0];
            var length      = point.Length(firstVertex.Point);

            Console.WriteLine(length);
            if (length < 15)
            {
                if (_newPolygon.Vertices.Count >= 3)
                {
                    _started = false;
                    var  lastEdgePoints = GetLine(firstVertex.Point.X, firstVertex.Point.Y, _lastVertex.Point.X, _lastVertex.Point.Y);
                    Edge lastEdge       = new Edge(_lastVertex.Id, lastEdgePoints);
                    _lastVertex.Edges[1] = firstVertex.Edges[0] = lastEdge;
                    lastEdge.Vertices[0] = _lastVertex;
                    lastEdge.Vertices[1] = firstVertex;

                    _newPolygon.Edges.Add(lastEdge);

                    var points = new List <Point>();
                    foreach (var edge in _newPolygon.Edges)
                    {
                        points.AddRange(edge.Points);
                    }
                    var colors = _mainTexture.GetAreaPixels(points);
                    DrawPoints(points, Color.Black, colors);

//                    DrawPoints(lastEdge.Points,Color.MidnightBlue);
                    CommitDraw();
                    _polygonFilling = ScanLine.PolygonFilling(_newPolygon.Vertices.Select(v => v.Point).ToList(), out var colorTab);
                    ExecuteFilter();
//                    RedrawImage();
                }

                return;
            }

            //When it is time time to add not-start vertex
            var  newVertex  = new Vertex(_lastVertex.Id + 1, point);
            var  edgePoints = GetLine(_lastVertex.Point.X, _lastVertex.Point.Y, point.X, point.Y);
            Edge newEdge    = new Edge(_lastVertex.Id, edgePoints);

            _lastVertex.Edges[1] = newVertex.Edges[0] = newEdge;
            newEdge.Vertices[0]  = _lastVertex;
            newEdge.Vertices[1]  = newVertex;

            _newPolygon.Vertices.Add(newVertex);
            _newPolygon.Edges.Add(newEdge);

            //Drawing line and point
//            DrawDot(point, Color.Crimson);
            DrawPoints(newEdge.Points, Color.Red);
            CommitDraw();

            _lastVertex = newVertex;
        }