Grid image values to 2D array
Asked Answered
A

1

2

I have a grid like the image below which I want to put in an array in this format:

 ;x = wall(black cells and grey boxes), s= start (red circle), g = goal(blue circle), 0 = available path(everything else)
 $data[5][5] = [["x","x","x","x","x"], _
               ["x","s","0","x","x"], _
               ["x","x","0","x","x"], _
               ["x","x","0","g","x"], _
               ["x","x","x","x","x"]]

image

I thought I could use the colors but I'm not sure how.

Antibiotic answered 3/5, 2015 at 17:45 Comment(0)
T
2
  1. looks like you have the view with fixed angles

    create function that converts screen position to grid position and back. It should be easy just 2x linear interpolation. if the camera pan is not with cell based step then you need the corner point of grid lines and use that as a start point ...

    for example something like this (hope I measured the pixels correctly):

    grid function

    x = 236 + (+(u-uh)-(v-vh))*60;
    y = 133 + (-(u-uh)-(v-vh))*30;
    
    • 60,30is the cell size in x,y
    • (236,133) is position of center of mid cell (uh,vh) in pixels
    • uh,vh are coordinates in your grid of center cell

    add the views pan offset to (uv,hv) or (236,133) now just compute the also the reverse transform from this (u=?,v=?). Do not forget that the map is not rectangle! It is something like this:

        0000x0000,
        000xxx000,
        00xxxxx00,
        0xxxxxxx0,
        xxxxxxxxx,
        0xxxxxxx0,
        00xxxxx00,
        000xxx000,
        0000x0000,
    
  2. create a set of images of all objects that you can encounter

    this can be done on the run, each time you do not found a match add cell to item list as new object type.

  3. loop through all grid cell locations and compare to object types

    for pixel precise rendered images you can compare directly pixels 1:1 if that is not the case the you need to compare objects more robustly. But to make a valid algorithm we need to see all the types of object you can encounter usually you can compare:

    1. average,min and max colors, histograms,
    2. aspect ratio,...
    3. FFT/DCT
    4. center of mass position,density, and more

    do not forget to mask comparison to area of cell only to not include the neighboring cells on corners of bounding rectangle

[Notes]

Can not be more specific without further info

Threnode answered 4/5, 2015 at 7:40 Comment(2)
The reason why I want to create this 2D array is because I want to be able to use a path finding algorithm. I found a working one at autoitscript.com/forum/topic/…. The camera will never move and the image is always the same sizeAntibiotic
@Antibiotic Take a look at Improving performance of click detection on a staggered column isometric grid I think it might interests you I share my C++ isometric engine source there it might get handy for you ...Threnode

© 2022 - 2024 — McMap. All rights reserved.