This question already has answers here:
Java Program using 4D array [closed]
(8 answers)
Closed 9 years ago.
I have been studying Java and C++ this year, and I am wondering; what practical uses are there for a 4 or even 5 dimensional array? My teacher basically says that you are using the wrong datatype if you want to use a 4 dimensional array.
Have you ever used a 4 of 5 (or more) dimensional array? What did you use it for? What practical uses can you think of for them?
Thanks!
A practical use of a 4D array is to keep track of a 3d object, could keep track of [x-cord][y-cord][z-cord][time]. This 4D array would be a useful use of a 4D array. This could keep track of a range of cords and time, and the value in the array could say the speed of of the object.
Speed = arr[5][9][6][1500];
That would record the speed of the object when it was at x cord 5, y cord 9, z cord 6, and say been alive for 1500 seconds.
As for your 5D array:
int left; //#of cars left in world
left = allCars[year][brand][color][condition][horsepower];
brand count be an int(have a table of values aka Ferrari = 1, same with color. Condition could be on a scale of 0 being destroyed, to 1 being brand new).
Then you could find the # of 1947 Ferrari's that are red in brand new condition with 200 horsepower.
Aka in general you could use many dimensional arrays to keep track of large databases of things.
You may create a Sodoku hypercube with 4 dimensions and then you can store the number which the user enters into a 4dimensional int array.
Rotating 4D hypercube (GIF movie). Imagine a person who lives in 4
spatial dimensions, watching a hypercube rotate. The 4-dimensional
person has a 3-dimensional retina in each of its 2 eyes (two eyes
suffice for depth perception, even in 4D). Each retina records a
3-dimensional image.
This image shows what the 4-dimensional person sees, with the extra
dimension shown as a variation in colour. That is, the horizontal,
vertical, and `colour' directions correspond to the 3 directions on
the 3-dimensional retina of the 4-dimensional person. The vertical bar
to the right of the picture shows the correspondence between colour
and position in the extra dimension.
Also you may check the Tesseract
Take almost anything from physics, where tensors are common, for example general relativity, computational chemistry, quantum physics.
http://en.wikipedia.org/wiki/Tensor#Applications
Tensor with rank 4 is common for example.
http://www.oonumerics.org/FTensor/FTensor.pdf
http://mpqc.svn.sourceforge.net/viewvc/mpqc/trunk/mpqc/src/lib/chemistry/qc/lmp2/lmp2.cc?revision=9342&view=markup&pathrev=9492
The example was a stock-keeping system where jeans could be indexed by
inventory[size][length][color][fit] = number_received
which is only slightly contrived. You'd have no problem with a database structured in such a way but it does look funny as code.
You might be running a geophysics simulation, where you have a 3D region such as an oil field, and you are measuring the relative quantities of different substances found at different points in the region (oil, water, sand, porous rock and so on). You might have three dimensions for the position, and one dimension for which substance you're looking at.
Related
Hi to all of you my friends. First of all , i already know java so i think i'll stick to that but anyways. I'm creating a facial recognition program and I'm just starting with opencv. I'm learning the Class "Mat" and what it means, here's the definition.
The class Mat represents an n-dimensional dense numerical single-channel or multi-channel array. It can be used to store real or complex-valued vectors and matrices, grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms.
I'm trying to learn what a single-channel or multi-channel array mean but i can't find information online for whatever reason. Can you explain this concept to me maybe linking some useful websites?
Thank you, Mattia (aka DJack)
single-channel or multi-channel can be understood by simple daily life examples.
Suppose you have two rectangular-shaped slices of bread.
Put the first bread on the floor in a vertical way(standing bread on the side).
And look from the top, the thing you will find is the single channel.
again, put the second piece of bread in the same way but parallel to the first bread ( parallel in the horizontal plane).
Now again look from the top, you will see two pieces of bread this time, this represents 2 channel matrix.
click on this link to see an image which is a 3 channel matrix
This is a 3 channel 8 bit unsigned integer.
This array consists of tuples with 3 elements.
For example :
{54,0.34} - first tuple
{58,78,185} - second tuple and so on.
but in the single channel matrix, you will get only one element. like 58, 78 etc.
Directly from the comment by #Dan MaĊĦek solves your problem:
Number of channels means:
how many values are used to represent a single element (e.g. pixel in a picture). For example, grayscale image represents each pixel by 1 value (intensity), so it will be stored as a single channel Mat. RGB image needs 3 values (red, green and blue), hence it needs a 3 channel Mat. RGBA has 4 values per pixel, so 4 channel image.
Let us say the status of a Connect4 game is stored like 12341, which means player 1 dropped his ball in position 1, and then player 2 in position 2, player 1 in position 3, player 2 in position 4 and player 1 in position 1 again.
In this format, is there an algorithm that can know if a game is won, in a way that is better than converting into a 2-d matrix and using the algorithms that is already listed in SO, like Connect 4 check for a win algorithm?
The characteristics of the game connectivity are such that the most effective method is to convert to the 2D paradigm to check for wins. The fastest method for most people is to check the current move in all directions, to see whether it just created a win.
You can somewhat improve the "intelligence" of the checking, by keeping a list of "live" lines -- possible future wins -- and checking to see which ones the most recent move extends or blocks.
Note that this is a less obvious approach for both coding and maintenance. Also, it's slower than checking the current move in all directions. It's really useful only if used to create an automatic player (AI).
For the sake of argument, let's say I want to place a wall object (for simplicity, let's pretend it's just a 1x1 square) on a 2d grid which is 20x20. Let's say I have the object modeled out in coordinates between 0 and 1.
So, my question is, using openGL in the correct manner (I realize there are plenty of ways I could change the coordinates manually, but that doesn't edify me for the future), how do I place this object on the grid in the location (5,5)? Would it be related to the model matrix?
Yes, I think you have the right idea.
If your wall exists in model space from (0,0) to (1,1), and you want to position a particular instance of this wall at (5,5) through (6,6), than an appropriate thing to do would be to draw this wall with a Model Matrix that is translated by 5 units in the x and y direction.
You should not use the transformation matrices to place single primitives. Everytime you change a uniform (aka matrix) it's very likely the rasterizer pipline must be flushed, which is a sure performance killer.
As a general rule, to be efficient, a given transformation matrix should be applied to at least 100 primitives within a scene. So if you have some grid of tiles, it's better to either duplicate-translate them into a larger Vertex Array, or use instancing (if available).
I'm making a project for a course at university. It's some kind of rpg which consists out of 3 dimensional dungeons. every dungeon is a cube holding squares. Now what I need to do is "collect" all squares from the sides of the cube.
I could easily do this by making 6 for loops but I don't think thats a very elegant way of doing this.
Does anyone know a better way of solving this problem then by using a ton of for loops?
If you have data in 3 dimensions, the most obvious way to store that information is in a 3 dimensional structure like a 3-dimensional array. That would allow you easily select all items at the 6 sides of the cube by getting all blocks where either a dimension is 0 or maximum. Where maximum is the size of the array.
However, this is all highly speculative without a bit of code. Maybe if you post what you have now it will help get you some more concrete answers.
You can iterate over two dimensions and do all 6 faces at once.
for (u...) {
for (v...) {
add(cube[0][u][v];
add(cube[M][u][v];
add(cube[u][0][v];
add(cube[u][M][v];
add(cube[u][v][0];
add(cube[u][v][M];
}
}
I understand how quad trees work on square images (by splitting the image until the section is a single colour, which is stored in the leaf node).
What happens if the image has one dimension longer that the other, you may end up with a 2x1 pixel area as the smallest sub unit, making it difficult to use quadtree division methods to store a single colour. How would you solve this issue?
You could pad the image until it is an equal and power of two size. While it may add some extra memory requirements, the increase shouldn't be that large.
The 2x1 example would be padded to a standard 2x2 and store the real size or use a special value for padded nodes so you can restore the original size.
Why don't you allow empty leafes in your tree?
Edit:
Maybe i don't understand the question^^. Your problem is that you end up with a non square images like 2x1 and want to represent them as a quadtreenode?
When you have a 2x2 square like
1 2
3 4
you would create a Quadnode with something like "new QuadNode(1,2,3,4)"
I would suggest to handel a 2x1 square like
1 2
with something like "new QuadNode(1,2,null,null)"
When you have bigger missing pieces you can use the same system. When you have a 4x2 picture like
1 2 3 4
5 6 7 8
you would get a "new QuadNode(new QuadNode(1,2,3,4),null,new QuadNode(5,6,7,8),null)"
This should also work with pieces with equal color instead of pixels.
Did i understand your problem and made myself clear?
A square is a special rectangle, Quad trees work on rectangles, too.
You just need a split method which gives 4 rectangles for a given one.
In case the top most root quad cell is an rectangle, just divide the width and height by 2.
In case of pixels, it makes only sense if the root cell widthand height are both a power of 2.
So if root cell = 2048 * 1024
The split just divides both width and height by 2.