You only need to calculate or know the distance between 2 vertices (in each dimension). Then you don't have to interact with any more vertex or terrain related stuff because of the regular terrain structure. You can do something as follows instead:

VECTOR terrain_min,terrain_max,mouse_terrain_pos;
var terrain_cell_size_x,terrain_cell_size_y,mouse_cell_x,mouse_cell_y;

fill terrain_min and terrain_max appropriately,
calculate terrain_cell_size_x/y via ent_getvertex or something like terrain_cell_size_x = (terrain_max.x-terrain_min.x)/(number of vertices in dimension x - 1);

then now calculate mouse_terrain_pos on the terrain (via c_trace or a line equation) and get the cell ids as follows:
mouse_cell_x = floor((mouse_terrain_pos.x-terrain_min.x)/terrain_cell_size_x); // same for y

You can now use mouse_cell_x/y to draw a quad on the terrain (or place a quad sprite there) and perform further calculations:
quad.x = (mouse_cell_x+0.5)*terrain_cell_size_x; // same for y. 0.5 because I assume quad is a sprite


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends