Without having some code that does this (and not enough time to write some now) I can only give a few pointers.
I usually start anything 3D by considering the easier 2D equivalent, so for this we are trying to find the height of a point on a line in a right angled triangle IE :-
2
|\
O| \______height to find
| |\H
| | \
3-4--1
--A1--
-A2-
A1/A2 = adjacents, which we know (distance between points 1&3 / 1&4)
O = opposite, which we know (distance between point 3 & 2)
H = Hypotenuse, which we don`t know, or care about.
Using SOHCAHTOA we can use:-
Tan(angle) = O / A1 (where A1 = distance between point 1 & 3 And O is the height between points 3 & 2)
To find the angle between the opposite and adjacent at 1 (Note: you could pre-calc these and store in an array)
Then Using SOHCAHTOA again we can use:-
Tan(angle) = O / A2 (Where A2 = distance between point 1 & 4 and O is the height we want to find)
To find the height we want (O in this case)
Thats just the start of it, you still need to swap the equations round to get the numbers out, and adapt it to 3D (although you can probably cheat a bit with that, if your scape is constructed the same as DB`s matrix`s).
Hope this helps a bit, you could also try looking at the info here:-
http://http://www.programmersheaven.com/zone10/mh96.htm