Finding grid sector from coordinates
-
I’d been looking at FLLocator for a while trying to figure out what maths it was using, but along comes Cannon with the problem already solved in the player control plugin.
Just thought I would put this here so I don’t lose it, and maybe it will be useful to somebody else. Adapted to C# from C++, but is easy to implement in other languages:
static string gridReferenceFromPos(int vPosX, int vPosZ, float systemScale = 1.0f) { string[] gridLabelX = { "A", "B", "C", "D", "E", "F", "G", "H" }; int[] gridLabelZ = { 1, 2, 3, 4, 5, 6, 7, 8 }; float fGridSize = 34000.0f / systemScale; int gridRefIntX = (int)((vPosX + (fGridSize * 5)) / fGridSize) - 1; int gridRefIntZ = (int)((vPosZ + (fGridSize * 5)) / fGridSize) - 1; if (gridRefIntX >= 0 && gridRefIntX < 8 && gridRefIntZ >= 0 && gridRefIntZ < 8) return gridLabelX[gridRefIntX] + gridLabelZ[gridRefIntZ].ToString(); else return "ERR"; }
The systemScale float comes from the system definition in universe.ini - if the system doesn’t have one, it’s 1.0f (default).