+ Reply to Thread
Results 1 to 7 of 7

Morton codes get errors when running

  1. #1
    Registered User
    Join Date
    06-26-2016
    Location
    Barcelona
    MS-Off Ver
    Office 2007
    Posts
    21

    Morton codes get errors when running

    Hello

    I have a code for calculating the Morton code. To convert a certain set of integer coordinates to a Morton code, you have to convert the decimal values to binary and interleave the bits of each coordinate as shown in the image that I attach.

    The code is supposed to work fine but I can't find out how to run it, it should ask for the 3 numbers but get errors please can you tell me how to run this code?

    Please Login or Register  to view this content.
    Attached Images Attached Images

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: Morton codes get errors when running

    After 24 hours, I will venture a couple of observations.

    Revealing my ignorance, but my first observation is that this does not look like VBA. If this code is supposed to be functional without modification, then my first question is "what programming language is this?" From there, running the code should be as "simple" as obtaining a compiler for that programming language, compiling the code, and running it.

    If I were starting from scratch doing something like this (in an Excel environment) I would probably:

    1) Use Excel's DEC2BIN() function to convert the decimal numbers to binary.
    2) Use Excel's MID() of VBA's Mid() function to extract individual characters from the binary numbers.
    3) Concatenate the result in the desired order.

    There are some details to figure out there, but I am not sure if that is how you want to approach the problem or not. In some of my research, I found some concepts that are over my head ("bitwise processing" for example), and you may be looking for that kind of implementation.

    I guess at this point I would ask for further clarification. Exactly what do you need help with? Are you required to use the code that you posted and you need help identifying the programming language and obtaining a compiler? Are you trying to translate this code as close as possible into VBA and/or Excel functions? Is this just sample code, and you will accept any approach that successfully encodes/decodes Morton code?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    06-26-2016
    Location
    Barcelona
    MS-Off Ver
    Office 2007
    Posts
    21

    Re: Morton codes get errors when running

    Thanks a lot for your reply, I'm not asked to use the code I posted, I need any working code to calculate the Morton codes, I got this code that works fine but calculates it for values lower than 15.
    Now I only need to extend the following code for numbers higher than 15 but I was not able to do it. I run it step by step in the excel that I attach here with all the values that the variables get but I did
    not get the correct result for (x,y,z) = (5,9,1) should be 1095 and I got 1096

    Please Login or Register  to view this content.
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: Morton codes get errors when running

    I copied the code you give an pasted it into a module in your spreadsheet. I then entered =Morton(A1,A2,A3) into A7, and the function returned 1095, which, if I understand correctly, is the value you think it should return. This is different from the spreadsheet version where S5 calculates 1096.

    So, I modified your code with a simple Stop statement at the beginning:
    Please Login or Register  to view this content.
    With the Stop statement in place, I executed the function (select A7, press F2 and enter) and enter debug mode. Then, while stepping through the function, I compared what the function was doing with the spreadsheet version. (If you are unfamiliar with VBA's debugging tools: http://www.cpearson.com/excel/DebuggingVBA.aspx ). The difference between the UDF and the spreadsheet version seems to be in column K. When the UDF got to the same point as K3, it added S2 and J3. The spreadsheet version added S2 and J2. It appears to me that K3 should be =S2+J3 (and copied down) instead.

  5. #5
    Registered User
    Join Date
    06-26-2016
    Location
    Barcelona
    MS-Off Ver
    Office 2007
    Posts
    21

    Re: Morton codes get errors when running

    Thanks, you are right, my excel was wrong.
    Please one last thing I'm trying to change the Morton function to work with numbers higher than 15, now it works for 4 bits
    I think it is because the "i" values ranging from 1 to 4 but when I change that I get the wrong mod operations and the "e" values

    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: Morton codes get errors when running

    Can you supply an example with the incorrect results as well as the expected correct results? I changed the 4 to 8, tested on x=18, y=59, z=5 and the function gave me 79134. Expanding your spreadsheet breakdown and I also get 79134. If 79134 is the correct answer for this particular problem, it should be as easy as changing the For i=... statement. If 79134 is not the correct result, then we need to know what the correct result should be, and, perhaps, some of the intermediate values along the way in order to debug.

  7. #7
    Registered User
    Join Date
    06-26-2016
    Location
    Barcelona
    MS-Off Ver
    Office 2007
    Posts
    21

    Re: Morton codes get errors when running

    Thanks so much MrShorty! I've created another example in an excel with DEC2BIN and concatenating, tried with the numbers you said: x=18, y=59, z=5 and the result is indeed 79134
    So it works fine!
    Thank you!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] how to add cost codes and add running totals to a cell
    By kwguy in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-29-2016, 05:36 PM
  2. [SOLVED] Errors with codes/formulas - Beginner mistake?
    By an Engineer in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 06-30-2015, 08:26 AM
  3. [SOLVED] Running codes with buttons from sheet2
    By wayneao in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-18-2014, 10:13 AM
  4. excel hang when running the below codes
    By nihallo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-06-2012, 11:22 PM
  5. Errors when running sheets
    By fred2028 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-25-2012, 02:23 AM
  6. Running total from mixed codes in Columns.
    By trownson in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-27-2010, 11:48 PM
  7. Running VBA codes in Excel 2007
    By tbaker897 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2008, 07:02 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1