Calculating 2D and 3D vector size of map gridSolved

I'm currently writing a plugin where I need to calculate the size of a map grid (so I can place a MapMarkerGenericRadius marker on the map the size of a full grid) and then calculate the radius for a zone represented by that map marker in the world (using ZoneManager).

I know that based on my current map size (3500), a circle to cover the map grid is roughly a radius of 60 and the radius of the zone in the world is roughly 75, but I'm looking for the best way of calculating it.

Currently, for the map marker, I'm using 1 - (sqrt(worldsize / 2) / 100), and that's nearly perfect, but I'm probably getting lucky and it may be off if I move to a larger or smaller map. After getting close with the map marker, I just trial and error'd my way to figuring out the radius for the zone in the world and 75 seemed to be a close fit.

Is there an exact calculation for this? Thanks in advance!

Found my answer. Grid is 150 regardless of world size, so radius of a circle would be half that. The reason that the map marker needs to be smaller is because the marker prefab already has a non-zero size, so it just needs to be shrunken down to account for it when setting it's radius.

To help everyone else, the second post wasn't the solve either. If you want to draw a map marker that covers an entire grid on the map, apparently there's scaling at play that works off of orders of magnitude based on the world size.

Here's a snippet of code to calculate it:

private float CalculateRadius()
{
    var a = 100f / 6f;
    var b = Mathf.Sqrt(a) / 2f;
    var c = World.Size / 1000f;
    var d = b / c;

    return d;
}
And here's the explanation:

Grids are 150m^2, so we start with the lowest world size of 1000. Doing integer math, 1000 / 150 gives us 6. This means that the map will be 6x6 grids in size. We then need to scale that down by an order of magnitude by dividing by 10. So the variable 'a' above is just a shortcut to do that all in one step. We then need to take the square-root of that number (we need the linear width/height so we need to take the square-root of the square) and cut it in half (we're dealing with a radius, so half of the width of the grid), which is what variable 'b' represents. The variable 'c' then gives us how many orders of magnitude of 1000 the current world size is. (So for a map of 3500, that would be 3.5). Lastly, we take the variable 'b' and divide it by the orders of magnitude of 1000 to get our final radius for the map marker. I've tested this with map sizes of 1000, 2000, 2500, 3000, 3500, 3800, and 4250, and it works in all of those cases.

If there's a better calculation for this, please chime in.
Locked automatically