I am not very good mathematical so how I would do it :

divide terrain in to 2d chunk rectangles, divide those boxes in to 2d rectangles based on the size of each cell in the chunk ..(quad tree like)

keep that data/list in memory.

to find the rectangle to draw where the mouse is inside , first determine which chunk rectangle the mouse position is inside , then determine which of the cells inside that chunk ,contains the mouse position.

retrieve the relevant information of that cell,like position/min/max , then draw it ..

jb


Compulsive compiler