# Storing a 3-dimensional array on a flat image

This topic is 5040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I could have posted this in the isometric forum, but since it is a theoretical problem rather then a graphical problem, I've posted it here. image 1: image 2: I've have a set of tiles that can be described by the following (see images):
• Each tile has three corners.
• Each of these corners has a certain color (in the image I've used 5 different colors, but that's totally arbitrary), a color can appear on a tile more than once (3 red corners for example).
What I need is one large image that contains every possible tile in an ordered way. By 'ordered' I mean that I can retrieve the position of a tile by using an algortihm. However, there are two more conditions that have to be met:
• I can't rotate a tile (and that way decreasing the number of tiles).
• Tiles cannot overlap: a bounding square of a tile should not include a part of another tile (see second image).
I've been thinking about this for quit some time now, but I don't seem to get to a solution. Since it contains three corners it can be easily stored in 3d array, so in code I wouldn't have a problem. But in an image... The only reasonable approach I came up with, is to create 5 ( == number of colors) seperate images and create a normal 2d-array of tiles in each image. This however would lead to duplicate tiles in different images. Since all this is a critical part of a game (I'll announce it when finished [smile]), I really have to nail this problem. I welcome any suggestion.

##### Share on other sites
Quote:
 Original post by WanMasterThe only reasonable approach I came up with, is to create 5 ( == number of colors) seperate images and create a normal 2d-array of tiles in each image. This however would lead to duplicate tiles in different images.
I don't follow how this would lead to duplicate tiles. I think this should work perfectly fine.

And you could actually just combine each of these individual images into one big image, or just have a super wide, one-tile-high image, and still manage any number of dimensions. Let's say that the width of one tile is 32 pixels. And lets say that you have 5 colors. Then, as you pointed out, you have three dimensions, based on the colors of the three corners. If the colors are numbered 0 through 4, and any tile can be represented by a 3-tuple (a, b, c), then the x-location of any given tile within the image could be (a * 5 * 5 + b * 5 + c) * 32. The y-location would always be 0 (of the top-left of the tile, of course). Make sense?

##### Share on other sites
Quote:
 Original post by Agony(a * 5 * 5 + b * 5 + c) * 32.

But ofcourse! How stupid am I?
I guess I was focusing too much on putting them into a 2d-grid. The method I used did lead to duplicates. I won't go into that, since it would take another long explanation and hey, the problem is solved.
And I can still adjust this formula a little to allow me to use multiple rows. It would make the image a little easier to manage.

Thank you very much!

1. 1
Rutin
47
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632994
• Total Posts
3009769
• ### Who's Online (See full list)

There are no registered users currently online

×