Calculating distance 
EC=GD
ABCD=Square with length a
Searching DH

How do I calculate DH in the most simplific way?
I tried to do it with functions and point D as the 2d origin. But I feel that is not the best way.
Could someone give me a hint in the right direction?
My attempt
squarelength=a
EC=y
GD=b
g=straight through E and D
h=straight through G and A
$D=(0,0)$
$g(x)=mx+d$
$g(0)=0$
$EC=e$
$g(a)=e=m\times a+d$
$d$ is 0 (since it goes through (0,0))
$m=\frac{g(a)-0}{a-0}=\frac{y}{a}$

$g(x)=\frac{y}{a}* x$

$h(x)=m*x+d$
$h(0)=-a$
therefore $d=-a$
$h(-b)=0$
$m=\frac{0-(-a)}{-b-0}=\frac{a}{-b}=-\frac{a}{b}$

$h(x)=-\frac{a}{b}*x-a$

Now calculating where g and h meet.
$g(x)=h(x)$
$\frac{y}{a}* x=-\frac{a}{b}*x-a$
$x=\frac{-a}{\frac{y}{a}+\frac{a}{b}}$
Now getting the coordinates:
$g(\frac{-a}{\frac{y}{a}+\frac{a}{b}})=\frac{y}{a}* \frac{-a}{\frac{y}{a}+\frac{a}{b}}$
Therefore the two straights meet at $(\frac{-a}{\frac{y}{a}+\frac{a}{b}},\frac{y}{a}* \frac{-a}{\frac{y}{a}+\frac{a}{b}})$
Now getting the distance from the origin (=DH)
$DH=\sqrt{(\frac{-a}{\frac{y}{a}+\frac{a}{b}})^2+(\frac{y}{a}* \frac{-a}{\frac{y}{a}+\frac{a}{b}})^2}$
Is this right?

 A: Hint 1: Show that $\Delta DCE$ is similar to $\Delta DHG$. In order to show this, show that the line $EH$ is perpendicular to the line $GA$. 
Hint 2: By similarity, the following ratios of lengths of the sides holds:
$$ \frac{|HD|}{|GD|} = \frac{|DC|}{|DE|}.$$
Note that $|DE|$ can be expressed in terms of $|DC|$ (which equal tot $a$) and $|CE|$ (which is the same as $|GD|$).
A: First, note that $\triangle ADH\sim\triangle EDC$ as $m\angle ECD = m\angle DHA$ since they are right angles, and $m\angle ADH = m\angle DEC$ since $$m\angle HDE = 180^\circ = m\angle HDA + m\angle EDC + 90^\circ\to m\angle HDA + m\angle EDC = 90^\circ$$
So, by CPCTC, $$\frac a{\overline{ED}} = \frac{\overline{AH}}a\to a^2 = \overline{AH}\cdot\overline{ED}$$
Through similar logic, we find $\triangle GDA\sim\triangle EDC$. However, we also know that $\overline{DA}=\overline{DC}$, hence $\triangle GDA\equiv\triangle EDC$. Hence, $$\overline{GD}=\overline{EC}=\frac{a^2}{\overline{AH}}$$
Finally, we can also show $\triangle GHD\sim\triangle ECD$. You can finish the proof from here.
A: If $EC =b$ then:
Let $C(0,0)$ and $D(-a,0)$ and $E(0,b)$, then $G(-a-b,0)$, $B(0,-a)$ and $A(-a,-a)$.
Line $DE$ has equation: $${x\over -a}+{y\over b} =1 \implies y={b\over a}x+b $$ and line $AG$ has equation: $$y=-{a\over b}(x+a+b)$$
So we have $$x_H=-{a^3+a^2b+ab^2\over a^2+b^2}  $$
so $$y_H=-{ab^2\over a^2+b^2}  $$
Then $$HD ={ab\over \sqrt{a^2+b^2}}$$
