Help with MAP LOGIC

Discussion in 'Chit Chat' started by Cableguy, May 30, 2008.

  1. Cableguy

    Cableguy Expert Licensed User

    I'm trying to make sense of some map Logic...
    Imagine a map, divided in cells, extending from -250 to 250, including 0,in both x and y axes...
    Its easy obtaining the total amount of squares.
    (250*250+1) will give me the number of Lines and of collumns, so the total amout of cell is (rows*Collumns)....
    In this case:
    501*501=251001

    For some reason, I HAVE TO USE THIS IN A SEARCH, but Then it gets complicated....
    How do I get the Coordinates for a specific cell, trough its number...
    Imagine I need to convert cell 36862 to X:Y , HOW????
     
  2. klaus

    klaus Expert Licensed User

    Hi Paulo,
    Here you are.

    Code:
    index=36862
    row=Int(index/
    501)
    col=index 
    Mod 501
    Best regards
     
    Last edited: May 31, 2008
  3. Cableguy

    Cableguy Expert Licensed User

    Thanks, but it shed litle light for what i need..
    you forgot that I have negative values, referenced to a 0 colun and a 0 row, so my map look a litle like this:

    -3 -2 -1 0 1 2 3
    +--+--+--+--+--+--+--+
    3 |01|02|03|04|05|06|07|
    +--+--+--+--+--+--+--+
    2 |08|09|10|11|12|13|14|
    +--+--+--+--+--+--+--+-
    1 |15|16|17|18|19|20|21|
    +--+--+--+--+--+--+--+
    0 |22|23|24|25|26|27|28|
    +--+--+--+--+--+--+--+
    -1 |29|30|31|32|33|34|35|
    +--+--+--+--+--+--+--+
    -2 |36|37|38|39|40|41|42|
    +--+--+--+--+--+--+--+
    -3 |44|45|46|47|48|49|50|
    +--+--+--+--+--+--+--+

    Only a LOT larger...
     
    Last edited: May 31, 2008
  4. klaus

    klaus Expert Licensed User

    No problem.

    The previous code
    Code:
    index=36862
    row=Int(index/
    501)
    col=index 
    Mod 501
    becomes

    Code:
    rowo=-177     ' row
    colo=39       ' col
    row0=-250     ' first row number
    col0=-250     ' first col number 
    rownb=501     ' number of rows
    colnb=501     ' number of cols
    index=(rowo-row0)*colnb+col0)  ' =36862  cell index

    row=Int(index/
    501)+row0   ' calculated row
    col=index Mod 501+col0    ' calculated col
    Best regards
     
  5. Cableguy

    Cableguy Expert Licensed User

    Yes, it works fine, but could you explain a bit your logic...
    How the actual calculations works....
     
  6. klaus

    klaus Expert Licensed User

    Hi Paulo,

    I have joined a Word file with some explanations, hope its more clear.

    Best regards.
     
    Last edited: Jun 1, 2008
  7. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Klaus you must be a math-magician!
    I like Cableguy couldn't see how your code works, but the explanation was great and you made it look so simple. Personally I hate maths and always struggle with it :)

    Regards,
    RandomCoder
     
  8. klaus

    klaus Expert Licensed User

    Hi RandomCoder,
    I am glad to hear that my explanations were clear.
    I am an engineer and of course like maths.

    Best regards.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice