3D Terrain get Z


I'm trying to make work a 3d terrain.
(I admit I was using 2d arrays until yesterday, then I've discovered ds_grid. Off topic ends now!)

Simply, I have no problem making 3d terrain using primitives, I even managed to get it from heightmap but I struggle at getting the Z coordinate.

Getting just the Z from the nearest coordinate is not smooth. Trying to solve it with very tiny triangles is a bad idea and it fries the GPU.

I came up with an idea to get the Z according to the Zs from the current triangle's 3 corners and by the distance to them. By misusing my mathematican friends, I would probably manage to get it work but it still doesn't sound like the best way to do it.

Please, what is the best way to get the Z from the 3d terrain?