0

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:

enter image description here

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) enter image description here 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

John McMullen
  • 77
  • 1
  • 8
  • So, while playing around with a few possible solutions, I decided to try utilizing polar coordinates to find a rotated position on the map. So i take the supplied content x and y, find the polar coordinates, rotate by 45 degrees, and then change back to Cartesian. Then find which cell those coordinates belong to This works well for values up to 15...however once you get out beyond 50, 100, etc etc, the values returned are several cells off, making the overall functionality flawed. Just thought I'd post on this, In case anyone else thinks of that idea... – John McMullen May 30 '14 at 17:45

1 Answers1

0

So you're really working with two primary parts: "cell coordinates" and "content coordinates". To me, this seems rather confusing because using the (X,Y) system for both cells and content is the same which can create potential problems. You need to separate the two. For example, have letters (A,B,C,D) for cell coordinates and numbers for content coordinates. Although, on second thought, it doesn't really seem necessary to have both at all. Whether you should keep both depends on your reasoning for using them in the first place.

The first chart that you provided is very inaccurate, so I hope it's only an example to explain your method for solving the problem. The cell locations are incorrect. If the cell coordinates are incorrect, nothing else will make sense. I digress.

I think your question is somewhat circular: "When i'm trying to find what the CellX and CellY are when given a set of coordinates... you cant solve the Cell X without the Cell Y"

Well...when you're "given a set of coordinates" don't you have the information that you need? If your true question is "how do I locate a set of coordinates using a different set of coordinates?" then that's a different question. If that's your question, then the answer is to your other question is - it depends on if the desired coordinates are located differently both on the X and Y axis. If the desired Cell (the cell that you're looking for) is only in one direction, then you only need one coordinate given your system. For example, if I tell you to drive North (latitude) 5 miles in your car, you don't exactly need to know the East/West (longitude)...because you're just driving North.

It looks to me like you need to make sure your charting system is solid. If you're charting system is off then it doesn't matter what coordinates you have. Practice plotting points on graph paper and calculating "Slope" like we all did in high-school. Using the formula for finding slope will help you figure this stuff out.

BTW - I'm not an expert on this stuff by any means and I don't have any experience in the gaming industry (programming, anyway). However, I do program frequently and studied a fair amount of calc in college.

sparky
  • 106
  • 7
  • Basically, the reason for the multiple coordinate setups, is because the map is set up in a dynamically loading cell-based system (which is the grid that is standard x and y). The problem comes in when organizing the objects in the game itself. As everything is isometric, and needs to be 'overlapped', every other row is essentially a change in the y (which is why it is angled in the chart) The first chart is actually precisely accurate, which is why its becoming difficult This is the 'live' demo I'm working out (shows the layout in-game) http://mc1.empirebattles.com/map/jquery_map.html – John McMullen May 30 '14 at 12:30