# How to get cartesian coords of objects from tiled's isometric map?

Hello, I’m working on simple isometric engine. But I don’t understand how to convert coords of objects from Tiled to cartesian coords. For example: In file:

I’m using a simple formaula for drawing tiles:

``````screen.x = (map.x - map.y) * TILE_WIDTH_HALF;
screen.y = (map.x + map.y) * TILE_HEIGHT_HALF;
``````

Could you please provide a formula for converting or a basic algorithm how work coords in Tiled?

Is your map “Isometric” or “Isometric (staggered)”? The coordinates work differently in each.

If it’s the regular isometric, the same question was asked just a few days ago:

It is “Isometric”. I saw that topic thanks. But I want to get exact coordinates (not column and row).

For example, in a file my object is represented:

``````<object id="7" x="154" y="36" width="50" height="50"/>
``````

I think maybe to use column and row and a offset. But I can’t derive a correct formula for the offset.

This is the Tiled code that does the translation from isometric tile coordinates to pixels. As you can see here, the location depends on both x and y, as well as the map’s height.

``````QPointF IsometricRenderer::tileToScreenCoords(qreal x, qreal y) const
{
const int tileWidth = map()->tileWidth();
const int tileHeight = map()->tileHeight();
const int originX = map()->height() * tileWidth / 2;

return QPointF((x - y) * tileWidth / 2 + originX,
(x + y) * tileHeight / 2);
}
``````

Thank you! I find it!

``````QPointF IsometricRenderer::pixelToScreenCoords(qreal x, qreal y) const
{
const int tileWidth = map()->tileWidth();
const int tileHeight = map()->tileHeight();
const int originX = map()->height() * tileWidth / 2; // it doesn't need in my code
const qreal tileY = y / tileHeight;
const qreal tileX = x / tileHeight;

return QPointF((tileX - tileY) * tileWidth / 2 + originX,
(tileX + tileY) * tileHeight / 2);
}

QPolygonF IsometricRenderer::pixelRectToScreenPolygon(const QRectF &rect) const
{
QPolygonF polygon;
polygon << QPointF(pixelToScreenCoords(rect.topLeft()));
polygon << QPointF(pixelToScreenCoords(rect.topRight()));
polygon << QPointF(pixelToScreenCoords(rect.bottomRight()));
polygon << QPointF(pixelToScreenCoords(rect.bottomLeft()));
return polygon;
}
``````

My object has coords: X: 134.0, Y: -91.0

2 Likes