示例#1
0
文件: Drone.cs 项目: rakrob/GridNav
        private Grid.Edge circleEdgeCollision(float X, float Y, float R, Grid.Obstruction rect)
        {
            PointF P = new PointF(X, Y);

            Grid.Edge E1 = new Grid.Edge(rect.originX, rect.originY, rect.originX + rect.width, rect.originY);
            Grid.Edge E2 = new Grid.Edge(rect.originX + rect.width, rect.originY, rect.originX + rect.width, rect.originY + rect.height);
            Grid.Edge E3 = new Grid.Edge(rect.originX + rect.width, rect.originY + rect.height, rect.originX, rect.originY + rect.height);
            Grid.Edge E4 = new Grid.Edge(rect.originX, rect.originY + rect.height, rect.originX, rect.originY);

            //use the point-line theorem to calculate distance between our drone center and each edge of the obstruction
            //normally we'd transpose into a new coordinate system but since all of our obstructions are axis aligned we're going to go with some slight fudgery here
            //this can be changed in the future
            if (Distance(P, E1) <= R && P.X >= rect.originX && P.X <= rect.originX + rect.width)
            {
                return(E1);
            }
            if (Distance(P, E2) <= R && P.Y >= rect.originY && P.Y <= rect.originY + rect.height)
            {
                return(E2);
            }
            if (Distance(P, E3) <= R && P.X >= rect.originX && P.X <= rect.originX + rect.width)
            {
                return(E3);
            }
            if (Distance(P, E4) <= R && P.Y >= rect.originY && P.Y <= rect.originY + rect.height)
            {
                return(E4);
            }

            return(null);
        }
示例#2
0
文件: Drone.cs 项目: rakrob/GridNav
        private Grid.Corner circleCornerCollision(float X, float Y, float R, Grid.Obstruction rect)
        {
            PointF P = new PointF(X, Y);

            Grid.Corner C1 = new Grid.Corner(rect.originX, rect.originY, rect.originX + rect.width / 2, rect.originY + rect.width / 2);
            Grid.Corner C2 = new Grid.Corner(rect.originX + rect.width, rect.originY, rect.originX + rect.width / 2, rect.originY + rect.width / 2);
            Grid.Corner C3 = new Grid.Corner(rect.originX + rect.width, rect.originY + rect.height, rect.originX + rect.width / 2, rect.originY + rect.height - rect.width / 2);
            Grid.Corner C4 = new Grid.Corner(rect.originX, rect.originY + rect.height, rect.originX + rect.width / 2, rect.originY + rect.height - rect.width / 2);

            if (Length(new PointF(C1.Vertex.X - P.X, C1.Vertex.Y - P.Y)) <= R)
            {
                return(C1);
            }
            if (Length(new PointF(C2.Vertex.X - P.X, C2.Vertex.Y - P.Y)) <= R)
            {
                return(C2);
            }
            if (Length(new PointF(C3.Vertex.X - P.X, C3.Vertex.Y - P.Y)) <= R)
            {
                return(C3);
            }
            if (Length(new PointF(C4.Vertex.X - P.X, C4.Vertex.Y - P.Y)) <= R)
            {
                return(C4);
            }

            return(null);
        }