ForHosting KIT · Developer Utilities

Point to hex grid cell

Convert a planar coordinate into the cell that contains it on a regular hexagonal grid.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

Provide the point, the hexagon size, and optionally the grid orientation and origin. The result gives integer axial column and row indices that can be used directly for maps, games, spatial bins, procedural layouts, and neighbor calculations. The conversion uses cube-coordinate rounding, so points near edges and corners are assigned consistently without scanning cells or constructing polygon geometry.

Define the grid before locating the point

A regular hexagonal grid needs three pieces of information before a point can be assigned to a cell. First, provide the planar x and y coordinates in the same coordinate system used by the grid. Second, set size to the distance from the center of a hexagon to any of its corners. This is the circumradius, not the full width, height, side-to-side spacing, or center-to-center distance. Third, choose the orientation. A pointy grid has a corner at the top and bottom, while a flat grid has a horizontal top and bottom edge. The default is pointy. By default, axial cell zero, zero is centered at planar coordinate zero, zero. Use origin_x and origin_y when the grid is translated elsewhere. The origin changes only the placement of the grid; it does not change its scale, orientation, or indexing. All coordinate and size values must use one consistent unit, such as pixels, meters, or projected map units. Geographic longitude and latitude should first be projected when a genuinely planar, distance-consistent grid is required.

Understand the axial result and rounding

The returned column and row are axial coordinates, commonly described as q and r in hex-grid literature. Axial coordinates use two integer axes even though movement on a hexagonal grid has six directions. The omitted third cube coordinate is implied as the negative sum of the first two, which makes distance, neighbor, ring, and range operations straightforward. Internally, the point is transformed into fractional axial coordinates according to the selected orientation. Those fractions are converted to cube coordinates, rounded while preserving the cube constraint, and converted back to an integer axial pair. This is important because independently rounding the two visible axes can select the wrong cell near a diagonal boundary. A point exactly on a shared edge or vertex belongs geometrically to more than one closed polygon, so any cell assignment needs a tie rule. This calculator resolves such ties deterministically through JavaScript numeric rounding and the fixed cube-component correction order. For ordinary interior points, the result is the unique containing cell; for exact boundaries, it is a stable canonical choice suitable for repeatable indexing.

Use cell indices in spatial systems

Once a point has an axial column and row, applications can group many observations without storing or testing every hexagon polygon. A game can convert pointer positions into board cells, a visualization can aggregate projected events into bins, and a procedural generator can use the pair as a stable tile key. Keep the original grid definition beside the indices: the same column and row identifies a different physical region if size, orientation, or origin changes. When processing multiple points, call the conversion with identical grid settings for every item and group records by a key such as column followed by a comma and row. Negative indices are normal; they simply identify cells to the left, above, or below the chosen axial origin, depending on orientation. The operation is constant time for each point and does not depend on the total grid extent. It also imposes no artificial boundary, so it works for finite boards and conceptually infinite grids alike. For rendering, derive each selected cell's center or polygon corners with the matching axial-to-planar formulas rather than treating column and row as rectangular pixel coordinates.

Select a hex tile from a pointer

Convert a mouse, stylus, or touch coordinate into the axial cell used by a board, editor, or strategy game.

Bin projected map observations

Assign planar map points to stable hexagonal buckets before counting, coloring, or summarizing observations.

Key procedural world data

Turn a position into integer column and row indices that can address generated terrain, caches, or simulation state.

What does size mean?

Size is the distance from a hexagon's center to any corner. For a regular hexagon, it is also the side length.

What is the difference between pointy and flat orientation?

Pointy hexagons have top and bottom corners. Flat hexagons have horizontal top and bottom edges. The coordinate conversion differs between them.

Can column or row be negative?

Yes. Axial coordinates extend naturally in every direction from cell zero, zero, so negative indices are expected.

What happens when a point lies exactly on a cell boundary?

The cube-rounding procedure applies a deterministic tie rule and returns one of the cells sharing that edge or vertex.

Can I provide longitude and latitude directly?

The calculation accepts numbers, but it assumes a planar coordinate system. Project geographic coordinates first when consistent distances and areas matter.

How much does an API request cost?

Each API request costs $0.002. The same deterministic calculation can also run in the browser.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/geo/hex-grid-cell

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/geo/hex-grid-cell \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"x":18,"y":9,"size":10}'
{
  "x": 18,
  "y": 9,
  "size": 10
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "geo.hex_grid_cell",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →