Similarities between triangles that share the same incircle I know this question may be based on programming but its core is geometry hence I am posting it here.
Okay what I am trying to do is to write a small program to find out all the possible triangles that have the same incircle radius.
One important condition is that all the units will be in integers. That is to say the ratio between the area and semi-perimeter must be a fully divisible with each other. The area calculated by Heron's formula must be a perfect square root. Also the perimeter must be fully divisible by 2. No rounding off, values with floating points are discarded entirely.
Following the above conditions the two scalene triangles share the same incircle ie. of radius 2.
5 12 13
6 8 10

Do they have any similarities ? What is the maximum area of the triangle that can contain an incircle of radius $r$ ?
What I am doing right now is actually checking all triangles starting with sides $2r$ to $2r*100$. Its basically a brute-force. But is there a better way of determining where I should stop ?
EDIT:
Just found this algo in CodeChef for this problem. Can someone explain to me how it works ? Or whats the logic behind it is ?
for x = 1 to 2*r-1 do:
    for y=x to (3*(r*r))/x do:
        p = (r*r)*(x+y)
        q = x*y-(r*r)

        if q <= 0
          perform next iteration of inner loop

        else
            z = p/q

            if (z < y or p mod q ! = 0)
                perform next iteration of inner loop

            else
                points for the triangle are
                x+y
                x+z
                z+y
       end inner loop
end outer loop

Here $r$ is the radius of the incircle. And mod means the remainder when I divide by the divisor(Its a programming operator). For example 4 mod 2 = 0, 4 mod 3 = 1
Please note I come from a computer science background so I am not that much familiar with the mathematical language, so if the above algo seems difficult to understand in the fashion I have given it then please let me know what I can do to better present it. 
 A: The triangles you are looking for are either Pythagorean triangles or a sum of two (possibly scaled) Pythagorean triangles.
To see that, one can show first of all that any Pythagorean triangle has an integer inradius. Any primitive Pythagorean triple $(a,b,c)$ can be obtained from two coprime integers $m$ and $n$ (not both odd and with $m>n$) as:
$$
a=m^2-n^2,\quad b=2mn,\quad c=m^2+n^2,
$$
and the Pythagorean triangle derived from that triple has inradius
$$
r={ab\over a+b+c}=n(m-n),
$$
which is indeed an integer. 
Of course, a multiple $(ka,kb,kc)$ of that Pythagorean triple will still give a triangle with integer inradius $r'=kr$.
In general, a triangle with integer sides and area also has rational altitudes. The altitude relative to the largest side falls inside the base and divides then the triangle into two right-angled triangles. Those triangles have integer hypotenuses, a rational cathetus common to both, and the other catheti whose sum is an integer, so they must be (rational multiples of) Pythagorean triangles.
EDIT.
For example, a triangle with sides $AC=9$, $BC=10$, $AB=17$, has an inradius of $2$ but is not Pythagorean. Let $CH$ be the altitude with respect to base $AB$: its length is $72/17$, which is a rational number. By Pythagoras' Theorem we also get: $AH=135/17$ and $BH=154/17$, so that triangles $ACH$ and $BCH$ are rescaled Pythagorean triangles, with sides:
$$
\left(9,{135\over17},{72\over17}\right)={9\over17}\left(17,15,8\right)
\quad\hbox{and}\quad
\left(10,{154\over17},{72\over17}\right)={2\over17}\left(85,77,36\right),
$$
and inradii $27/17$ and $28/17$ respectively.
I don't know if the above is relevant or not for your search: I tried to find a simple relation between the inradius of the composite triangle and the inradii of its two constituents, but without success. At the moment, I think a brute-force approach is still preferable to find all triangles with a given inradius.
EDIT 2.
That piece of code makes sense.
Tangency points divide triangle sides into $6$
parts (equal pairwise), whose lengths are $x$, $y$ and $z$
(see diagram below).
Let $2\alpha$, $2\beta$ and $2\gamma$ the angles formed by the radii joining incenter with tangency points, so that $x=r\tan\alpha$, $y=r\tan\beta$, $z=r\tan\gamma$, and suppose $x\le y\le z$. The largest value of $x$ is attained when $\alpha=\beta=\gamma=60°$, so we have a first bound: 
$$x\le r\tan 60°=\sqrt3 r.$$
Once $x$ is given, the largest value of $y$ is reached when $\beta=\gamma=90°-\alpha/2$, whence a second bound: 
$$
y\le r\tan(90°-\alpha/2)={r^2+r\sqrt{x^2+r^2}\over x}\le{3r^2\over x}.
$$
Finally, once $x$ and $y$ are given one can compute:
$$
z=r\tan(180°-\alpha-\beta)={r^2(x+y)\over xy-r^2}.
$$
Notice that in the code the first and second bound are used in a weaker form, possibly for the sake of simplicity. But for large values of $r$, using the optimal bounds given above:
$$
1\le x\le \sqrt3 r,
\quad
x\le y \le {r^2+r\sqrt{x^2+r^2}\over x},
$$
could result in a faster execution.

