Exemplo n.º 1
0
        /// <summary>
        /// 利用反向算法得到含有两次不相邻绕射的路径中的各个点详细位置信息
        /// </summary>
        /// <param name="indexOfPath">所要计算的路径的下标</param>
        /// <param name="indexOfEdge1OfThisPath">第一次绕射节点所在下标位置信息</param>
        /// <param name="indexOfEdge2OfThisPath">第二次绕射节点所在下标位置信息</param>
        /// <returns>按路径经过顺序存储的各个点的坐标</returns>
        private List <Point> GetPointsOfContainTwoNoAdjacentDiffractPath(int indexOfEdge1OfThisPath, int indexOfEdge2OfThisPath)
        {
            List <Point> pointList = new List <Point>();

            for (int i = 0; i < this.node.Count - 2; i++)
            {
                pointList.Add(new Point());
            }
            Stack <Face> reflectTrianglesBeforeDiffract = new Stack <Face>(), reflectTrianglesForMirrorBeforeDiffract = new Stack <Face>(),
                         reflectTrianglesAfterDiffract = new Stack <Face>(), reflectTrianglesForMirrorAfterDiffract = new Stack <Face>(),
                         reflectTrianglesBetweenDiffract = new Stack <Face>();
            Stack <Point> mirrorPointsBeforeDiffract = new Stack <Point>(), mirrorPointsAfterDiffract = new Stack <Point>(),
                          mirrorPointsBetweenDiffract = new Stack <Point>();
            Stack <AdjacentEdge> mirrorDiffractEdge   = new Stack <AdjacentEdge>();

            //预处理绕射棱前后的三角面和点
            DealTrianglesAndPointsBeforeAndAfterDiffractEdge(indexOfEdge1OfThisPath, indexOfEdge2OfThisPath,
                                                             reflectTrianglesBeforeDiffract, reflectTrianglesAfterDiffract, mirrorPointsBeforeDiffract, mirrorPointsAfterDiffract);

            //求绕射两棱前后的镜像点
            PushTrianglesAndMirrorPoints(reflectTrianglesBeforeDiffract, reflectTrianglesForMirrorBeforeDiffract, mirrorPointsBeforeDiffract);
            PushTrianglesAndMirrorPoints(reflectTrianglesAfterDiffract, reflectTrianglesForMirrorAfterDiffract, mirrorPointsAfterDiffract);
            mirrorPointsBetweenDiffract.Push(mirrorPointsBeforeDiffract.Peek());
            mirrorDiffractEdge.Push(this.node[indexOfEdge1OfThisPath].DiffractionEdge);


            AdjacentEdge updatedDiffractEdge2 = this.node[indexOfEdge2OfThisPath].DiffractionEdge;
            AdjacentEdge tempDiffractEdge2    = GetNewDiffractEdge(this.node[indexOfEdge2OfThisPath - 1].ReflectionFace,
                                                                   this.node[indexOfEdge2OfThisPath].DiffractionEdge, mirrorPointsAfterDiffract.Peek());//利用绕射棱前一三角面更新绕射棱信息

            updatedDiffractEdge2.StartPoint = tempDiffractEdge2.StartPoint;
            updatedDiffractEdge2.EndPoint   = tempDiffractEdge2.EndPoint;

            //作点和第一绕射棱关于两绕射棱之间的面的镜像
            for (int i = indexOfEdge1OfThisPath + 1; i < indexOfEdge2OfThisPath; i++)
            {
                reflectTrianglesBetweenDiffract.Push(this.node[i].ReflectionFace);
                mirrorPointsBetweenDiffract.Push(mirrorPointsBetweenDiffract.Peek().GetMirrorPoint(reflectTrianglesBetweenDiffract.Peek()));
                mirrorDiffractEdge.Push(new AdjacentEdge(mirrorDiffractEdge.Peek().StartPoint.GetMirrorPoint(reflectTrianglesBetweenDiffract.Peek()),
                                                         mirrorDiffractEdge.Peek().EndPoint.GetMirrorPoint(reflectTrianglesBetweenDiffract.Peek())));
            }

            List <Point> diffractPoints = GetTwoDiffractionPoints(mirrorDiffractEdge.Pop(), updatedDiffractEdge2,
                                                                  mirrorPointsBetweenDiffract.Pop(), mirrorPointsAfterDiffract.Peek());

            if (diffractPoints.Count() == 0)
            {
                return(new List <Point>());
            }

            pointList[indexOfEdge2OfThisPath - 1] = diffractPoints[1]; //第二绕射棱上绕射点坐标
            pointList[indexOfEdge2OfThisPath - 2] = GetReflectPoint(diffractPoints[0], diffractPoints[1], reflectTrianglesBetweenDiffract.Pop());
            if (pointList[indexOfEdge2OfThisPath - 2] == null)         //判断绕射棱前一三角面的反射点是否存在
            {
                return(new List <Point>());
            }

            if (reflectTrianglesBetweenDiffract.Count != 0)//两绕射棱间是否有未处理三角面
            {
                pointList[indexOfEdge2OfThisPath - 3] = GetReflectPoint(mirrorDiffractEdge.Pop().GetDiffractionPoint(
                                                                            mirrorPointsBetweenDiffract.Pop(), pointList[indexOfEdge2OfThisPath - 2]),
                                                                        pointList[indexOfEdge2OfThisPath - 2], reflectTrianglesBetweenDiffract.Pop());
                if (pointList[indexOfEdge2OfThisPath - 3] == null)
                {
                    return(new List <Point>());
                }
            }
            pointList[indexOfEdge1OfThisPath - 1] = this.node[indexOfEdge1OfThisPath].
                                                    DiffractionEdge.GetDiffractionPoint(mirrorPointsBeforeDiffract.Peek(), pointList[indexOfEdge1OfThisPath]);

            if (reflectTrianglesBeforeDiffract.Count != 0)//第一条棱前是否有反射点
            {
                pointList[indexOfEdge1OfThisPath - 2] = GetReflectPoint(
                    mirrorPointsBeforeDiffract.Pop(), pointList[indexOfEdge1OfThisPath - 1], reflectTrianglesBeforeDiffract.Pop());
                if (pointList[indexOfEdge1OfThisPath - 2] == null)
                {
                    return(new List <Point>());
                }
            }

            if (reflectTrianglesAfterDiffract.Count != 0)//第二条棱后是否有反射点
            {
                pointList[indexOfEdge2OfThisPath] = GetReflectPoint(pointList[indexOfEdge2OfThisPath - 1], mirrorPointsAfterDiffract.Pop(),
                                                                    reflectTrianglesAfterDiffract.Pop());
                if (pointList[indexOfEdge2OfThisPath] == null)
                {
                    return(new List <Point>());
                }
            }

            return(pointList);
        }