0

I have written the following code in c# where it calculates the Snake index of a 2-dimensional point.

    public static uint SnakeCurveIndex(uint bits, uint x, uint y )
    {

        uint index = 0;
        //The dimension of the array
        uint dim = (uint)Math.Pow( 2.0 , (double)bits);

        if(y % (uint)2 == 0 )
        {
            index = x + y * dim;

        }
        else
        {
            index = (dim - 1 - x) + y * dim;
        }
        if (index >= dim*dim)
        {
            //Debug console 
            throw new Exception("The index is out of bounds");
        }

        return index;
    }

The variable bits it responsible for the order of the curve. The following image represents the order of the curve for 1 to 3. enter image description here

My question is who to extend this code for n-dimensional points? Do I need a multidimensional-array or some other technique?

enter image description here

Thank you for your time.

aybe
  • 15,516
  • 9
  • 57
  • 105
  • define "snake" index? – Daniel A. White Jul 25 '20 at 20:39
  • hi, Meaby mine question it was not so clear. I have a 2-d data points and I wont to map those in 1 dimension where it is a line. For example, we have a point (x,y) = (2,2) and the Order of a curve is 2 then with the above code the index of this point is 11. In 2 dimension i know the ansers for eny given point. The following image shows the 3d snake curve :https://ibb.co/5h9vvHB . I wont to generalize the code for N dimensions and i dont know who to do that. – Giannis Aggelis Jul 25 '20 at 22:12
  • The code should return index+1 to match the images. To generalize it, you need to pass in an array of coordinates then use the array size to determine the dimension. In the code, you will need to loop through the dimensions. This may require recursion. – Mike67 Jul 26 '20 at 00:34

0 Answers0