Exemplo n.º 1
0
        /**
         * Convert a point to a grid index.
         */
        private int pointToGridIdx(Grid grid, float[] point)
        {
            int[]   idx  = new int[3];
            float[] size = grid.getSize();

            for (int i = 0; i < 3; ++i)
            {
                idx [i] = (int)Math.Floor((point [i] - grid.getMin() [i]) / size [i]);
                if (idx [i] >= grid.getDivision() [i])
                {
                    idx [i] = grid.getDivision() [i] - 1;
                }
            }

            return(idx [0] + grid.getDivision() [0] * (idx [1] + grid.getDivision() [1] * idx [2]));
        }
        /**
         * Convert a grid index to a point (the min x/y/z for the given grid box).
         */
        public static float[] gridIdxToPoint(Grid grid, int idx)
        {
            int[] gridIdx = new int[3];

            int ydiv = grid.getDivision()[0];
            int zdiv = ydiv * grid.getDivision()[1];

            gridIdx[2] = idx / zdiv;
            idx       -= gridIdx[2] * zdiv;
            gridIdx[1] = idx / ydiv;
            idx       -= gridIdx[1] * ydiv;
            gridIdx[0] = idx;

            float[] size  = grid.getSize();
            float[] point = new float[3];
            for (int i = 0; i < 3; ++i)
            {
                point[i] = gridIdx[i] * size[i] + grid.getMin()[i];
            }
            return(point);
        }
Exemplo n.º 3
0
        /**
         * Convert a point to a grid index.
         */
        private int pointToGridIdx(Grid grid, float[] point)
        {
            int[] idx = new int[3];
            float[] size = grid.getSize ();

            for (int i = 0; i < 3; ++i) {
                idx [i] = (int)Math.Floor ((point [i] - grid.getMin () [i]) / size [i]);
                if (idx [i] >= grid.getDivision () [i]) {
                    idx [i] = grid.getDivision () [i] - 1;
                }
            }

            return idx [0] + grid.getDivision () [0] * (idx [1] + grid.getDivision () [1] * idx [2]);
        }