# How to write a function that, when i give it the index of a cell, it calculates a position of corresponding grid cell?

Hello This is Mahsa,

I have a complected question about grid,
I want to write a function that, when i give the index of a cell,
calculate it and give the position of chosen cell, for example when i give cell
number 2 in that function calculate the cell number 2 base on the given width and height also (width is x axis, height is y axis)

Can Anyone help me ?

### IndexToCoord

``````public static Vector2Int IndexToCoord ( int i , int width ) => new Vector2Int( i%width , i/width );
``````

### CoordToPoint

``````public static Vector2 CoordToPoint ( int x , int y , float stepX , float stepY ) => new Vector2( x*stepX , y*stepY );
public static Vector2 CoordToPoint ( Vector2Int coord , float stepX , float stepY ) => CoordToPoint( coord.x , coord.y , stepX , stepY );
public static Vector2 CoordToPoint ( Vector2Int coord , Vector2 step ) => CoordToPoint( coord.x , coord.y , step.x , step.y );
``````