Question

Note: I define a 'Jagged Multidimensional' specifically as jmArray[][,].

I'm trying to wrap my head around the use of this type of array, in order to hold simple coordinates, a pair of Integers. This array will be used to create a 3x3 grid, so in my head I'm seeing:

jmArray[N][X,Y]

Where N is the number of the grid slice, and X,Y are the coordinates of the slice. So:

jmArray[2][3,2]

Would mean that slice 2 lies at coordinate 3,2.

I've been trying to assign values to each slice, but I'm stuck somewhere...

jmArray[0][,] = new int[1,2] {{3,3}};

A little help in understanding how to do this properly would be nice.

Was it helpful?

Solution

Unless I'm misunderstanding you, a simpler way to do this would be to create a dictionary of size 3 tuples.

var space = Dictionary<Tuple<int, int, int>, TPointValue>;

// Fill up space with some points
space[Tuple.Create(3,3,1)] = new TPointValue(42);

// Retrieve point from 3d space
TPointValue point3_3_1 = space[Tuple.Create(3,3,1)];

I'll concede that in its current form, this approach makes retrieval of planes or basis lines cumbersome and inefficient compared to jagged arrays, although it does makes assignment and retrieval of points very efficient.

However: if you were to wrap this data structure in a class of your own that provides methods for accessing planes/lines etc, you could very easily and efficiently calculate the keys required to obtain any set of points beforehand, eg. those within a plane/line/polygon, and then access these points very efficiently.

PS: Note that the value at a point need not be some fancy type like TPointValue, it could be just a string or float or whatever you like.

OTHER TIPS

You can achieve it like this:

int[][,] jmArray = new int[3][,];
jmArray[0] = new int[1,2] {{3,3}};

Instead of a complicated array a simple class with meaningful names might work better:

class Slice
{
    int X = 0;
    int Y = 0;
    public Slice()
    {
    }
    public Slice(int _X, int _Y)
    {
        X = _X;
        Y = _Y;
    }
}

Slice[] Slices = new Slice[9];

The index of the array will be the position of the slice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top