Ejemplo n.º 1
0
        public void CubicClassify(EntityCollection part)
        {
            this.Boundary   = part.Boundary;
            this.Dimentions = (Boundary[1] - Boundary[0]).ToArray();
            double longEdgeLength = (new double[] { Norm(new PointD(this.Dimentions[0], this.Dimentions[1], 0)), this.Dimentions[2] }).Max();
            double unit           = longEdgeLength / this.n;

            this.CubeDimentions      = new double[] { unit, unit, unit };
            this.CubeArrayDimentions = new int[] {
                (int)System.Math.Ceiling(Dimentions[0] / CubeDimentions[0]),
                n,
                (int)System.Math.Ceiling(Dimentions[2] / CubeDimentions[2])
            };
            this.CubeArrayLastIndex = new int[] {
                CubeArrayDimentions[0] - 1,
                CubeArrayDimentions[1] - 1,
                CubeArrayDimentions[2] - 1
            };

            CubeSpaces = new CubicSpace[CubeArrayDimentions[0], CubeArrayDimentions[1], CubeArrayDimentions[2]];
            for (int i = 0; i < CubeArrayDimentions[0]; i++)
            {
                for (int j = 0; j < CubeArrayDimentions[1]; j++)
                {
                    for (int k = 0; k < CubeArrayDimentions[2]; k++)
                    {
                        CubeSpaces[i, j, k] = new CubicSpace();
                    }
                }
            }

            //foreach (Entity entity in part.Entities.Values)
            //{
            //    PointD[] boundary = entity.Boundary;
            //    int[] startCubeIndex = GetCubicSpaceIndex(boundary[0]);
            //    int[] endCubeIndex = GetCubicSpaceIndex(boundary[1]);

            //    for (int i = startCubeIndex[0]; i <= endCubeIndex[0]; i++)
            //    {
            //        for (int j = startCubeIndex[1]; j <= endCubeIndex[1]; j++)
            //        {
            //            for (int k = startCubeIndex[2]; k <= endCubeIndex[2]; k++)
            //            {
            //                CubeSpaces[i, j, k].Add(entity);
            //            }
            //        }
            //    }
            //}
        }
Ejemplo n.º 2
0
        public void CubicClassify(EntityCollection part)
        {
            this.Boundary = part.Boundary;
            this.Dimentions = (Boundary[1] - Boundary[0]).ToArray();
            double longEdgeLength = (new double[] { Norm(new PointD(this.Dimentions[0], this.Dimentions[1], 0)), this.Dimentions[2] }).Max();
            double unit = longEdgeLength / this.n;
            this.CubeDimentions = new double[] { unit, unit, unit };
            this.CubeArrayDimentions = new int[]{ 
                (int)System.Math.Ceiling(Dimentions[0] / CubeDimentions[0]), 
                n, 
                (int)System.Math.Ceiling(Dimentions[2] / CubeDimentions[2]) };
            this.CubeArrayLastIndex = new int[]{ 
                CubeArrayDimentions[0] - 1, 
                CubeArrayDimentions[1] - 1, 
                CubeArrayDimentions[2] - 1 };

            CubeSpaces = new CubicSpace[CubeArrayDimentions[0], CubeArrayDimentions[1], CubeArrayDimentions[2]];
            for (int i = 0; i < CubeArrayDimentions[0]; i++)
            {
                for (int j = 0; j < CubeArrayDimentions[1]; j++)
                {
                    for (int k = 0; k < CubeArrayDimentions[2]; k++)
                    {
                        CubeSpaces[i, j, k] = new CubicSpace();
                    }
                }
            }

            //foreach (Entity entity in part.Entities.Values)
            //{
            //    PointD[] boundary = entity.Boundary;
            //    int[] startCubeIndex = GetCubicSpaceIndex(boundary[0]);
            //    int[] endCubeIndex = GetCubicSpaceIndex(boundary[1]);

            //    for (int i = startCubeIndex[0]; i <= endCubeIndex[0]; i++)
            //    {
            //        for (int j = startCubeIndex[1]; j <= endCubeIndex[1]; j++)
            //        {
            //            for (int k = startCubeIndex[2]; k <= endCubeIndex[2]; k++)
            //            {
            //                CubeSpaces[i, j, k].Add(entity);
            //            }
            //        }
            //    }
            //}
        }
Ejemplo n.º 3
0
        public void CubicClassify(EntityCollection part)
        {
            this.Boundary = part.Boundary;
            this.Dimentions =  (Boundary[1] - Boundary[0]).ToArray();
            double longEdgeLength = this.Dimentions.Max();
            double unit = longEdgeLength / this.n;
            this.CubeDimentions = new double[] { unit, unit, unit };
            this.CubeArrayDimentions = new int[]{ 
                (int)System.Math.Ceiling(Dimentions[0] / CubeDimentions[0]), 
                (int)System.Math.Ceiling(Dimentions[1] / CubeDimentions[1]), 
                (int)System.Math.Ceiling(Dimentions[2] / CubeDimentions[2]) };
            this.CubeArrayLastIndex = new int[]{ 
                CubeArrayDimentions[0] - 1, 
                CubeArrayDimentions[1] - 1, 
                CubeArrayDimentions[2] - 1 };
            
            //計算節點
            this.Nodes = new PointD[CubeArrayDimentions[0] + 1, CubeArrayDimentions[1] + 1, CubeArrayDimentions[2] + 1];
            for (int i = 0; i < CubeArrayDimentions[0] + 1; i++)
            {
                for (int j = 0; j < CubeArrayDimentions[1] + 1; j++)
                {
                    for (int k = 0; k < CubeArrayDimentions[2] + 1; k++)
                    {
                        this.Nodes[i, j, k] = new PointD()
                        {
                            X = Boundary[0].X + CubeDimentions[0] *i,
                            Y = Boundary[0].Y + CubeDimentions[1] * j,
                            Z = Boundary[0].Z + CubeDimentions[2] * k
                        };
                    }
                }
            }
            //建立方塊
            this.CubeSpaces = new CubicSpace[CubeArrayDimentions[0], CubeArrayDimentions[1], CubeArrayDimentions[2]];
            for (int i = 0; i < CubeArrayDimentions[0]; i++)
            {
                for (int j = 0; j < CubeArrayDimentions[1]; j++)
                {
                    for (int k = 0; k < CubeArrayDimentions[2]; k++)
                    {
                        CubeSpaces[i, j, k] = new CubicSpace() { Boundary = new PointD[] { this.Nodes[i, j, k], this.Nodes[i+1, j+1, k+1] } };
                    }
                }
            }

            foreach (Entity entity in part.Entities.Values)
            {
                PointD[] boundary = entity.Boundary;
                int[] startCubeIndex = GetCubicSpaceIndex(boundary[0]);
                int[] endCubeIndex = GetCubicSpaceIndex(boundary[1]);

                for (int i = startCubeIndex[0]; i <= endCubeIndex[0]; i++)
                {
                    for (int j = startCubeIndex[1]; j <= endCubeIndex[1]; j++)
                    {
                        for (int k = startCubeIndex[2]; k <= endCubeIndex[2]; k++)
                        {
                            CubeSpaces[i, j, k].Add(entity);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void CubicClassify(EntityCollection part)
        {
            this.Boundary   = part.Boundary;
            this.Dimentions = (Boundary[1] - Boundary[0]).ToArray();
            double longEdgeLength = this.Dimentions.Max();
            double unit           = longEdgeLength / this.n;

            this.CubeDimentions      = new double[] { unit, unit, unit };
            this.CubeArrayDimentions = new int[] {
                (int)System.Math.Ceiling(Dimentions[0] / CubeDimentions[0]),
                (int)System.Math.Ceiling(Dimentions[1] / CubeDimentions[1]),
                (int)System.Math.Ceiling(Dimentions[2] / CubeDimentions[2])
            };
            this.CubeArrayLastIndex = new int[] {
                CubeArrayDimentions[0] - 1,
                CubeArrayDimentions[1] - 1,
                CubeArrayDimentions[2] - 1
            };

            //計算節點
            this.Nodes = new PointD[CubeArrayDimentions[0] + 1, CubeArrayDimentions[1] + 1, CubeArrayDimentions[2] + 1];
            for (int i = 0; i < CubeArrayDimentions[0] + 1; i++)
            {
                for (int j = 0; j < CubeArrayDimentions[1] + 1; j++)
                {
                    for (int k = 0; k < CubeArrayDimentions[2] + 1; k++)
                    {
                        this.Nodes[i, j, k] = new PointD()
                        {
                            X = Boundary[0].X + CubeDimentions[0] * i,
                            Y = Boundary[0].Y + CubeDimentions[1] * j,
                            Z = Boundary[0].Z + CubeDimentions[2] * k
                        };
                    }
                }
            }
            //建立方塊
            this.CubeSpaces = new CubicSpace[CubeArrayDimentions[0], CubeArrayDimentions[1], CubeArrayDimentions[2]];
            for (int i = 0; i < CubeArrayDimentions[0]; i++)
            {
                for (int j = 0; j < CubeArrayDimentions[1]; j++)
                {
                    for (int k = 0; k < CubeArrayDimentions[2]; k++)
                    {
                        CubeSpaces[i, j, k] = new CubicSpace()
                        {
                            Boundary = new PointD[] { this.Nodes[i, j, k], this.Nodes[i + 1, j + 1, k + 1] }
                        };
                    }
                }
            }

            foreach (Entity entity in part.Entities.Values)
            {
                PointD[] boundary       = entity.Boundary;
                int[]    startCubeIndex = GetCubicSpaceIndex(boundary[0]);
                int[]    endCubeIndex   = GetCubicSpaceIndex(boundary[1]);

                for (int i = startCubeIndex[0]; i <= endCubeIndex[0]; i++)
                {
                    for (int j = startCubeIndex[1]; j <= endCubeIndex[1]; j++)
                    {
                        for (int k = startCubeIndex[2]; k <= endCubeIndex[2]; k++)
                        {
                            CubeSpaces[i, j, k].Add(entity);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public HashSet <CubicSpace> GetRay(PointD position, Vector direction)
        {
            PointD ssP = GetStanderCoordinate(position);
            Vector ssD = Normalize(GetStanderVector(direction));

            int[] Dquadrant    = Sign(direction.ToArray());
            int[] startIndex   = GetCubicSpaceIndex(position);
            int[] currentIndex = GetCubicSpaceIndex(position);

            HashSet <CubicSpace> Ray = new HashSet <CubicSpace>();

            #region XYZ射線距離計算
            {
                double Rate1 = Dot(ssD, new Vector(1, 0, 0)); //////////////////
                double Rate2 = Dot(ssD, new Vector(0, 1, 0)); //////////////////
                double Rate3 = Dot(ssD, new Vector(0, 0, 1)); //////////////////
                double v1    = Dquadrant[0] != 0 ? Rate1 * Abs(currentIndex[0] + Dquadrant[0] - ssP[0]) : double.PositiveInfinity;
                double v2    = Dquadrant[1] != 0 ? Rate2 * Abs(currentIndex[1] + Dquadrant[1] - ssP[1]) : double.PositiveInfinity;
                double v3    = Dquadrant[2] != 0 ? Rate3 * Abs(currentIndex[2] + Dquadrant[2] - ssP[2]) : double.PositiveInfinity;
                while (!((currentIndex[0] < 0 && Dquadrant[0] < 0) || (currentIndex[0] > CubeArrayLastIndex[0] && Dquadrant[0] > 0)) &&
                       !((currentIndex[1] < 0 && Dquadrant[1] < 0) || (currentIndex[1] > CubeArrayLastIndex[1] && Dquadrant[1] > 0)) &&
                       !((currentIndex[2] < 0 && Dquadrant[2] < 0) || (currentIndex[2] > CubeArrayLastIndex[2] && Dquadrant[2] > 0)))
                {
                    CubicSpace cubic = GetCubicSpace(currentIndex);
                    if (cubic != null)
                    {
                        Ray.Add(cubic);
                    }


                    int    Dir  = 0;
                    double minV = v1;
                    if (minV > v2)
                    {
                        Dir = 1;
                    }
                    minV = v2;
                    if (minV > v3)
                    {
                        Dir = 2;
                    }
                    minV = v3;

                    currentIndex[Dir] += Dquadrant[Dir];

                    if (Dir == 0)
                    {
                        v1 = Dquadrant[0] != 0 ?Rate1 * Abs(currentIndex[0] + Dquadrant[0] - ssP[0]) : double.PositiveInfinity;
                    }
                    else if (Dir == 1)
                    {
                        v2 = Dquadrant[1] != 0 ?Rate2 * Abs(currentIndex[1] + Dquadrant[1] - ssP[1]) : double.PositiveInfinity;
                    }
                    else if (Dir == 2)
                    {
                        v3 = Dquadrant[2] != 0 ? Rate3 * Abs(currentIndex[2] + Dquadrant[2] - ssP[2]) : double.PositiveInfinity;
                    }
                }
            }
            #endregion

            return(Ray);
        }