calculate x,y with index