# Some tips

### Placing ISO tiles on a map.

Placing ISO tiles might be a problem if you don't know how to handle them. In maps with rectangular tiles the checkbox "allow tile overlap" ensures that you can not place tiles that overlap.

If you use that checkbox (unchecked) in ISO mode, you can place only a tile on every "second" spacing" - this is not fun. (this happens since ISO tiles are made from normal "rectangle" tiles). To have a similar behaviour do the following:

- build a grid fitting for your ISO tiles

- enable the grid

- enable "snap" to grid

- check "allow tile overlap" (allowing overlap!)

- check "single position" (tiles in one map can not be placed on exactly the same position)

Voila - you can now easily place ISO tiles that don't overlap!

### Programmers point - where in an ISO-Map am I?

Maping mouse coordinates to the correct ISO tile seems to be one of the big questions of the 20th century. Here is how I do the correct mapping:

I will use an even, regular, complete and ordered ISO map.

height is the height of one ISO-tile, width... dito

I can divide the map in "half columns" and "half rows". I number these half rows and half columns and will have even and odd half columns. Easy example:
a ISO-tile might be 64x48 pixel
than even columns are: 0, 64, 128...
and odd columns are: 32, 96, 160...
(rows respectivly)

Than I know:

- the mapHeight of the map is (n+1/2)*height

- the mapWidth of the map is (m+1/2)*width

- every other row/column starts at an offset of 1/2 heigth or width

- each point lies "over" two rectangles of the tile map, one of the rectangles starts allways at an even half column and the other starts allways at an odd half column.

Since I have to start somewhere I calculate the "even" column for my point.

This is easly done by:
`int evenBaseX = (x/width)*width;
int evenBaseY = (y/height)*height;
`
The base is than the upper left corner (point 0,0 from the tile) of the tile.

The offset from that base to the point position I am interested in than is:
`int baseOffsetX=x%evenBaseX;
int baseOffsetY=y%evenBaseY;
`
Consider the following crude picture.

ISO Coordinates

The above calculated offsets all lie in one ISO-Rectangle. All I have to do now is determine the quadrants, which is also easily done:

`int quadrantColumnIndex = (x / (width/2) )%2;
int quadrantRowIndex = (y / (height/2) )%2;
`

Once I have the quadrant I can use an easy formular to determine where the point lies in respect to the diagonal.

You use a Vectorproduct, which is defined by:
`Vectorproduct: u x v = u.x * v.y - v.x * u.y
`

If you define the diagonal and the point we are interested in as follows. The diagonal line is defined by to points:
`u = line(i+1) - line(i)`

The point we are interested in, in relation to the line:
`v = p - line(i)`

The result of the vectorproduct gives us the answer whether the point is on the left side, the ride side or on the diagonal.
`
u x v < 0 => p lies left of the line
u x v = 0 => p lies on the line
u x v > 0 => p lies right of the line
`

One code example for the test in "stupidish java":
`
if ( (quadrantColumnIndex==0) && (quadrantRowIndex==0) )
{
int diagX1 = 0;
int diagY1 = height/2;
int diagX2 = width/2;
int diagY2 = 0;
int ux = diagX2-diagX1;
int uy = diagY2-diagY1;
int vx = x-diagX1;
int vy = y-diagY1;
int uxv = ux*vy-vx*uy;
if (uxv<0) return 1; / / 1 return means it is not on ISO tile in quadrant 1
return 0; / / 0 return means is on ISO-Tile
}`

If you do that for the correct quadrant you know that:

- either the even tile is correct (above returns 0)

- the neighbouring odd tile (in relation to the quadrant) is the correct tile

- (or null, if we are out of bounds)