示例#1
0
        internal bool isZero(Node.direction direction)
        {
            double x1, y1, x2, y2;

            CommonClass.Geography.calculatBaideMercatorIndex.getBaiduPicIndex(direction.start.BDlongitude, direction.start.BDlatitude, out x1, out y1);
            CommonClass.Geography.calculatBaideMercatorIndex.getBaiduPicIndex(direction.end.BDlongitude, direction.end.BDlatitude, out x2, out y2);
            var l = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));

            if (l > 1e-8)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#2
0
        public System.Numerics.Complex getComplex(Node.direction direction)
        {
            double x1, y1, x2, y2;

            CommonClass.Geography.calculatBaideMercatorIndex.getBaiduPicIndex(direction.start.BDlongitude, direction.start.BDlatitude, out x1, out y1);
            CommonClass.Geography.calculatBaideMercatorIndex.getBaiduPicIndex(direction.end.BDlongitude, direction.end.BDlatitude, out x2, out y2);
            // throw new NotImplementedException();
            var l = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));

            System.Numerics.Complex c;
            if (l > 1e-8)
            {
                c = new System.Numerics.Complex((x2 - x1) / l, (y2 - y1) / l);
            }
            else
            {
                throw new Exception("");
            }
            return(c);
        }
示例#3
0
文件: Path.cs 项目: sxtgyrq/VRPGame
        public Node GetAFromB_v2(int from, int to, RoleInGame player, ref List <string> notifyMsgs)
        {
            // throw new Exception("");
            int cursor = 0;//光标所在位置

            var path = this.GetAFromB_Path(from, to, player, ref notifyMsgs);

            if (path.Count > 1)
            {
                var lastPoint = path[0];//第一个点作为起点
                var node      = new Node()
                {
                    path = new List <Node.pathItem>()
                };//初始化node
                for (var indexOfPath = 0; indexOfPath < path.Count; indexOfPath++)
                {
                    if (indexOfPath + 1 < path.Count)
                    {
                        if (indexOfPath == 0)
                        {
                            /*
                             * 第一个点
                             */
                            var firstRoad = Program.dt.GetItemRoadInfo(path[0]);
                            if (firstRoad.CarInOpposeDirection == 1)
                            {
                                var right = new Node.direction()
                                {
                                    right = true,
                                    start = path[indexOfPath],
                                    end   = path[indexOfPath + 1]
                                };
                                //path[path]
                                if (thePointIsEnd(path[indexOfPath], path[indexOfPath + 1]))
                                {
                                }
                                var wrong = new Node.direction()
                                {
                                    right = false,
                                    start = path[indexOfPath + 1],
                                    end   = path[indexOfPath],
                                };
                                node.path.Add(new Node.pathItem()
                                {
                                    path = new List <MapGo.nyrqPosition>()
                                    {
                                    },
                                    selections = new List <Node.direction>()
                                    {
                                        right,
                                        wrong
                                    },
                                    position        = path[indexOfPath],
                                    selectionCenter = new Node.pathItem.Postion()
                                    {
                                        longitude = path[indexOfPath].BDlongitude,
                                        latitude  = path[indexOfPath].BDlatitude,
                                    }
                                });
                            }
                            else
                            {
                                var right = new Node.direction()
                                {
                                    right = true,
                                    start = path[indexOfPath],
                                    end   = path[indexOfPath + 1]
                                };

                                /*
                                 * 这里只有1个选项是为了不进行选择。
                                 */
                                node.path.Add(new Node.pathItem()
                                {
                                    path = new List <MapGo.nyrqPosition>()
                                    {
                                    },
                                    selections = new List <Node.direction>()
                                    {
                                        right
                                    },
                                    position        = path[indexOfPath],
                                    selectionCenter = new Node.pathItem.Postion()
                                    {
                                        longitude = path[indexOfPath].BDlongitude,
                                        latitude  = path[indexOfPath].BDlatitude,
                                    }
                                });
                            }
                            lastPoint = path[0];
                            cursor    = indexOfPath + 1;
                        }
                        else
                        {
                            var current  = Program.dt.GetItemRoadInfo(path[indexOfPath]);
                            var next     = Program.dt.GetItemRoadInfo(path[indexOfPath + 1]);
                            var position = lastPoint.copy();
                            if (current.RoadCode == next.RoadCode)
                            {
                                //   cursor = i;
                                List <CalCross> calCross = new List <CalCross>();

                                double ascendingValue;
                                if (path[indexOfPath].roadOrder + path[indexOfPath].percent < path[indexOfPath + 1].roadOrder + path[indexOfPath + 1].percent)
                                {
                                    ascendingValue = 1;
                                }
                                else if (path[indexOfPath].roadOrder + path[indexOfPath].percent > path[indexOfPath + 1].roadOrder + path[indexOfPath + 1].percent)
                                {
                                    ascendingValue = -1;
                                }
                                else
                                {
                                    continue;
                                }
                                {
                                    var findCrosses = findCrossesF(current.Cross1,
                                                                   current,
                                                                   path[indexOfPath], path[indexOfPath + 1], ascendingValue,
                                                                   (SaveRoad.DictCross c) =>
                                    {
                                        return(c.RoadCode1);
                                    },
                                                                   (SaveRoad.DictCross c) =>
                                    {
                                        return(c.RoadOrder1);
                                    },
                                                                   (SaveRoad.DictCross c) =>
                                    {
                                        return(c.Percent1);
                                    }
                                                                   );
                                    for (var indexOfC = 0; indexOfC < findCrosses.Count; indexOfC++)
                                    {
                                        calCross.Add(new CalCross()
                                        {
                                            cross   = findCrosses[indexOfC],
                                            calType = 1
                                        });
                                    }
                                }
                                {
                                    var findCrosses = findCrossesF(current.Cross2,
                                                                   current,
                                                                   path[indexOfPath], path[indexOfPath + 1], ascendingValue,
                                                                   (SaveRoad.DictCross c) =>
                                    {
                                        return(c.RoadCode2);
                                    },
                                                                   (SaveRoad.DictCross c) =>
                                    {
                                        return(c.RoadOrder2);
                                    },
                                                                   (SaveRoad.DictCross c) =>
                                    {
                                        return(c.Percent2);
                                    }
                                                                   );
                                    for (var indexOfC = 0; indexOfC < findCrosses.Count; indexOfC++)
                                    {
                                        calCross.Add(new CalCross()
                                        {
                                            cross   = findCrosses[indexOfC],
                                            calType = 2
                                        });
                                    }
                                }

                                calCross = (from item in calCross
                                            orderby(item.calType == 1 ? (item.cross.RoadOrder1 + item.cross.Percent1) : (item.cross.RoadOrder2 + item.cross.Percent2)) * ascendingValue ascending
                                            select item).ToList();
                                for (int indexOfCalCross = 0; indexOfCalCross < calCross.Count; indexOfCalCross++)
                                {
                                    var pathItem = new List <MapGo.nyrqPosition>();
                                    pathItem.Add(lastPoint.copy());//增加最后一点。
                                    for (int start = cursor; start < indexOfPath; start++)
                                    {
                                        pathItem.Add(path[start]);
                                    }
                                    cursor = indexOfPath + 1;//将光标指向下一个位置。在一个线段内的第二个cross,不会执行上面的循环
                                    var newLast = new MapGo.nyrqPosition
                                                  (
                                        calCross[indexOfCalCross].calType == 1 ? calCross[indexOfCalCross].cross.RoadCode1 : calCross[indexOfCalCross].cross.RoadCode2,
                                        calCross[indexOfCalCross].calType == 1 ? calCross[indexOfCalCross].cross.RoadOrder1 : calCross[indexOfCalCross].cross.RoadOrder2,
                                        calCross[indexOfCalCross].calType == 1 ? calCross[indexOfCalCross].cross.Percent1 : calCross[indexOfCalCross].cross.Percent2,
                                        calCross[indexOfCalCross].cross.BDLongitude,
                                        calCross[indexOfCalCross].cross.BDLatitude,
                                        lastPoint.maxSpeed);
                                    pathItem.Add(newLast);
                                    lastPoint = newLast.copy();
                                    Node.pathItem.Postion selectionCenter = new Node.pathItem.Postion()
                                    {
                                        longitude = calCross[indexOfCalCross].cross.BDLongitude,
                                        latitude  = calCross[indexOfCalCross].cross.BDLatitude,
                                    };
                                    var selections = new List <Node.direction>();
                                    if (ascendingValue > 0)
                                    {
                                        selections.Add(new Node.direction()
                                        {
                                            start = path[indexOfPath],
                                            end   = path[indexOfPath + 1],
                                            right = true
                                        });
                                        if (current.CarInOpposeDirection == 1)
                                        {
                                            selections.Add(new Node.direction()
                                            {
                                                start = path[indexOfPath + 1],
                                                end   = path[indexOfPath],
                                                right = false
                                            });
                                        }
                                    }
                                    else if (ascendingValue < 0)
                                    {
                                        selections.Add(new Node.direction()
                                        {
                                            start = path[indexOfPath],
                                            end   = path[indexOfPath + 1],
                                            right = true
                                        });
                                        selections.Add(new Node.direction()
                                        {
                                            start = path[indexOfPath + 1],
                                            end   = path[indexOfPath],
                                            right = false
                                        });
                                    }
                                    string otherRoadCode;
                                    int    otherRoadOrder;
                                    if (calCross[indexOfCalCross].calType == 1)
                                    {
                                        otherRoadCode  = calCross[indexOfCalCross].cross.RoadCode2;
                                        otherRoadOrder = calCross[indexOfCalCross].cross.RoadOrder2;
                                    }
                                    else
                                    {
                                        otherRoadCode  = calCross[indexOfCalCross].cross.RoadCode1;
                                        otherRoadOrder = calCross[indexOfCalCross].cross.RoadOrder1;
                                    }
                                    var otherRoad = Program.dt.GetItemRoadInfo(otherRoadCode, otherRoadOrder);

                                    selections.Add(new Node.direction()
                                    {
                                        start = new MapGo.nyrqPosition(otherRoad.RoadCode, otherRoad.RoadOrder, 0, otherRoad.startLongitude, otherRoad.startLatitude, otherRoad.MaxSpeed),
                                        end   = new MapGo.nyrqPosition(otherRoad.RoadCode, otherRoad.RoadOrder, 1, otherRoad.endLongitude, otherRoad.endLatitude, otherRoad.MaxSpeed),
                                        right = false
                                    });
                                    if (otherRoad.CarInOpposeDirection == 1)
                                    {
                                        selections.Add(new Node.direction()
                                        {
                                            end   = new MapGo.nyrqPosition(otherRoad.RoadCode, otherRoad.RoadOrder, 0, otherRoad.startLongitude, otherRoad.startLatitude, otherRoad.MaxSpeed),
                                            start = new MapGo.nyrqPosition(otherRoad.RoadCode, otherRoad.RoadOrder, 1, otherRoad.endLongitude, otherRoad.endLatitude, otherRoad.MaxSpeed),
                                            right = false
                                        });
                                    }

                                    node.path.Add(new Node.pathItem()
                                    {
                                        path            = pathItem,
                                        selections      = selections,
                                        position        = position,
                                        selectionCenter = selectionCenter
                                    });
                                }
                            }
                            else
                            {
                                var pathItem = new List <MapGo.nyrqPosition>();
                                pathItem.Add(lastPoint);
                                for (int start = cursor; start < indexOfPath; start++)
                                {
                                    pathItem.Add(path[start]);
                                }
                                cursor = indexOfPath + 2;//将光标指向下一个位置。在一个线段内的第二个cross,不会执行上面的循环
                                var newLast = path[indexOfPath].copy();
                                pathItem.Add(newLast);

                                var selections = new List <Node.direction>();
                                Node.pathItem.Postion selectionCenter = new Node.pathItem.Postion()
                                {
                                    longitude = path[indexOfPath].BDlongitude,
                                    latitude  = path[indexOfPath].BDlatitude,
                                };
                                selections.Add(new Node.direction()
                                {
                                    start = path[indexOfPath + 1],
                                    end   = path[indexOfPath + 2],
                                    right = true
                                });
                                if (next.CarInOpposeDirection == 1)
                                {
                                    selections.Add(new Node.direction()
                                    {
                                        start = path[indexOfPath + 2],
                                        end   = path[indexOfPath + 1],
                                        right = false
                                    });
                                }

                                selections.Add(new Node.direction()
                                {
                                    start = path[indexOfPath - 1],
                                    end   = path[indexOfPath],
                                    right = false
                                });

                                selections.Add(new Node.direction()
                                {
                                    start = path[indexOfPath],
                                    end   = path[indexOfPath - 1],
                                    right = false
                                });;
                                node.path.Add(new Node.pathItem()
                                {
                                    path            = pathItem,
                                    selections      = selections,
                                    position        = position,
                                    selectionCenter = selectionCenter
                                });
                                lastPoint = path[indexOfPath + 1].copy();
                            }
                        }
                    }
                }

                {
                    var pathItem = new List <MapGo.nyrqPosition>();
                    pathItem.Add(lastPoint);
                    for (var indexOfLeft = cursor; indexOfLeft < path.Count; indexOfLeft++)
                    {
                        pathItem.Add(path[indexOfLeft]);
                    }
                    var selections = new List <Node.direction>();
                    node.path.Add(new Node.pathItem()
                    {
                        path            = pathItem,
                        selections      = selections,
                        position        = lastPoint,
                        selectionCenter = new Node.pathItem.Postion()
                        {
                            longitude = path[path.Count - 1].BDlongitude,
                            latitude  = path[path.Count - 1].BDlatitude,
                        }
                    });
                }
                return(node);
            }
            else
            {
                /*
                 * 如果path.count=1或2,返回空结果。
                 */
                var node = new Node()
                {
                    path = new List <Node.pathItem>()
                };
                return(node);
            }
        }