Let's label the 3 points as A;B;C, where BC is the hypotenuse and AB is the shortest side, and x as AH.
We can see that triangle AHC is similar to triangle CAB, and triangle ACH is similar to triangle BCA, so therefore triangle AHC is similar to triangle CHA (i might've messed up the order but you get it)
Because they are similar, we get the ratio : x/12 = 40/x, or x^2 = 480.
So, x =
, or 21.9 (1 d.p)