Пример #1
0
        /// <summary>
        /// 读取segment节点信息
        /// </summary>
        private Segment readSegNode(XmlNode segNode)
        {
            Segment ans = new Segment();

            for (int i = 0; i < segNode.ChildNodes.Count; ++i)
            {
                XmlNode sub = segNode.ChildNodes[i];
                // 填充节点信息
                SimPoint simP = new SimPoint();
                for (int j = 0; j < sub.ChildNodes.Count; ++j)
                {
                    ValSet.SetModelValue(sub.ChildNodes[j].Name, sub.ChildNodes[j].InnerText, simP);
                }
                // 添加至左侧或者右侧
                if (sub.Name.Equals(MapInfo.detLS))
                {
                    ans.LeftP.Add(simP);
                }
                else
                {
                    ans.RightP.Add(simP);
                }
            }
            return(ans);
        }
Пример #2
0
        // add new left and rigth side point
        public void addPoint(SimPoint left, SimPoint righ)
        {
            int li = leftPs.Count - 1;
            int ri = righPs.Count - 1;

            if (li < 0 || ri < 0)
            {
                leftPs.Add(left);
                righPs.Add(righ);
            }
            else
            {
                if (leftPs[li].getDis(left) < 0.01 ||
                    righPs[ri].getDis(righ) < 0.01)
                {
                    return;
                }
                // 没有转向
                //if (MoveInfo.curTurn == MoveInfo.Turning.NoTurn)
                //{
                leftPs.Add(left);
                righPs.Add(righ);
                //leftEnd = righEnd = -1;
                //}
                //// 当前转向为向左转
                //else if (MoveInfo.curTurn == MoveInfo.Turning.TrunLeft)
                //{
                //    leftEnd = (leftEnd == -1) ? leftPs.Count : leftEnd;
                //    leftPs.Insert(leftEnd, left);
                //    righPs.Add(righ);
                //}
                //else if (MoveInfo.curTurn == MoveInfo.Turning.TurnRight)
                //{
                //    righEnd = (righEnd == -1) ? righPs.Count : righEnd;
                //    righPs.Insert(righEnd, righ);
                //    leftPs.Add(left);
                //}
            }
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        private void cutWorker(int start, int end, List <SimPoint> list, List <int> keys)
        {
            // too less points return
            if (end - start < 3)
            {
                return;
            }
            // recode the max value
            int    maxI = start;
            double maxV = 0;
            // every step change in x and y
            double perX = (list[end].x - list[start].x) / (end - start);
            double perY = (list[end].y - list[start].y) / (end - start);

            // find the max distance
            for (int i = start + 1; i < end; ++i)
            {
                SimPoint p    = list[i];
                double   curD = p.getDis(list[start].x + perX * (i - start),
                                         list[start].y + perY * (i - start));
                // compare and get the distance
                if (curD > maxV)
                {
                    maxV = curD;
                    maxI = i;
                }
            }
            if (maxV < range)
            {
                return;
            }
            // recode the special point and check the next one
            keys.Add(maxI);
            cutWorker(start, maxI, list, keys);
            cutWorker(maxI, end, list, keys);
        }
Пример #4
0
 /// <summary>
 /// Get the distance between two points
 /// </summary>
 public double getDis(SimPoint point)
 {
     return(this.getDis(point.x, point.y));
 }