First off, this isn't as much of a programming question (syntax and such), as it is just me trying to figure out an issue). So I apologize if this isn't the right area, or even the right site. For record, this is being calculated in php, with data gotten from sql database. I've been working on a map system that is an x-y coordinate system, however, the way that it is laid out is in 'cells', which are organized on a larger scale like a standard grid system (right is x+, up is y+) The tricky part, is the actual 'contents' are laid out with the x and y axis on an angle, making the general idea something like this:
The red lettering shows the "cell coordinates" (marked with the solid black outlines)
The black lettering inside the 'cells' is the content coordinates. cell 0,0 starts with content 0,0, and cell 0,1 starts with 5,5
The way this shows up in the product is something like this (cell is outlined--ignore the mis-matched river tiles)
The positioning is staggered for the overlap appearance. In the product the y axis runs nearly perfectly diagonal, and the x axis runs perpendicular.
I know that to find the content coord for the 'root' coord (relative 0,0) it goes something like this:
$contentRootX=($cellX+$cellY)*5;
$contentRootY=($cellY-$cellX)*5;
My issue is coming in, when i'm trying to find what the CellX and CellY are when given a set of coordinates. Unless my brain is abandoning my basic algebra and equations... you cant solve the CellX without the CellY which is why i've come here: does anyone have a solution, or even a simple workaround to be able to calculate the cell's X and Y.
side note: i have tried to do equation simplification, resulting in CellX=(X-5Y)/26 ... however that will return a decimal every time, and no matter how i round it (middle round, ceil, floor), it will return an invalid x response. Examples:
2,-3 (should return CellX=0). 0.653. The only valid action is to floor to get 0 Thus if you always floor the result, 0,10 would be an exception: -1.923 (should round UP to 1)....even in the same cell, another result would require rounding DOWN....So the standard equations aren't providing any info that I can work with... if you can find a pattern in the values returned by an equation, and find a way to distinguish between when you must round down and up, lemme know