How to draw an X in a tic-tac-toe square

This math will show the relationship between selected square and start/stop position required to draw lines in a square: