0

As the title suggest my problem lies in some representation of a sphere surface in computer memory. For simplicity, let's say we are making a chess game where the board is on a sphere. If the board was a classic flat board, then the solution is simple: use a 2D table.

But I don't know what kind of a memory structure I should chose for a sphere. Namely, what I want from this representation are:

  • If I move a pawn stubbornly in one direction, then I should return to the point where I started,
  • During such "journey" I should cross a point directly on the other side of the sphere (I mean to avoid a common "error" in a 2D game where moving pass an edge of a board will move an object to the opposite edge, thus making the board a torus, not a real sphere)
  • the area of one board cell should be approximately equal to any other cell
  • a cell should have got an associated longitude-latitude coordinates (I wrote "associated" because I want from the representation to only have got some way to obtain these coordinates from the position of a cell, not to be eg. a table with lat-long indexes)
Felix.leg
  • 622
  • 1
  • 4
  • 13
  • #2 is going to give you trouble, as a sphere doesn't map to a finite plane; there will always be a path with a singularity on it, a place where "one direction" stops making sense. For example, on Earth, you move stubbornly in a direction, north, then you reach the north pole. What direction are you going now? Figure out how you want to solve the singularity problem in your case, and that'll help narrow down your options. – Welbog Apr 26 '22 at 18:49
  • @Welbog well by "one direction" I didn't mean to keep going in a direction from a compass. If, for example, I chose a north as my direction then I go in this direction even if I reach a north pole. At the pole I simply start to go to south, then at the south pole I start to go north until I reach the starting point. What I meant in #2 was going along [a great circle](https://en.wikipedia.org/wiki/Great_circle) – Felix.leg Apr 26 '22 at 18:58
  • see [Location of highest density on a sphere](https://stackoverflow.com/a/25082674/2521214) and check the `ab2ij` and `ij2ab` conversion functions (`i,j` is cell index and `a,b` is lon,lat) – Spektre Apr 27 '22 at 06:32
  • 2
    I don't think you can map a sphere with quadrilaterals in a very regular way. You should try to draw your spherical board in 3d first, before you think about its 2d representation. – Stef Apr 27 '22 at 14:17
  • @Stef good point +1 but its still doable except on poles and except the grid layers will not join as on normal chess board see the quad grid on the link in my previous comment (so cells have more than just 8 neighbors ... I would go for the circles as it looks better – Spektre Apr 28 '22 at 05:35

1 Answers1

1

There's no simple geometric solution to this. The crux of the problem is that, say you have n columns at the equator, and you're currently near the north poll, and heading north. Then the combination of the direction and the column number from the top row (and second from top row) must be able to uniquely identify which one of the n positions at the equator that path is going to cross. Therefore, direction could not be an integer unless you have n columns in the top (or second to top) row. Notice that if the polygons have more than three sides, then they must have common edges (and triangles won't work for other reasons). So now you have a grid, but if you have more than three rows (i.e. a cube, or other regular prism), then moving sideways on the second-to-top row will not navigate you to the southern hemisphere.

The best bet might be to create a regular polyhedron, and keep the point and direction as floating point vectors/points, and calculate the actual position when you move, and figure out which polygon you land in (note, you would have the possibility of moving to non-adjacent polygons with this method, and you might have issues if you land exactly on an edge/vertex, etc).

HardcoreHenry
  • 5,909
  • 2
  • 19
  • 44