I am trying to create a program for a school project where I need to plot points of a triangle given all 3 side lengths (a=10, b=20, c=30).
By the triangle inequality $a + b > c$. In this case you have $a + b =c$. So this will be a straight line where $C$ is in a line in between $A$ and $B$.
I tried the solution from the other topic
WHAT other topic?
and it didn't work since the result produced was C(20,0)
That is correct. $A = (0,0)$ and $B = (30, 0)$ and $C = (20,0)$ then $a = BC = \sqrt{(30-20)^2 - (0-0)^2} = \sqrt{(10)^2} = 10$ and $b = AC = \sqrt{(0-20)^2 - (0-0)^2} = \sqrt{(-20)^2} = 20$ and $c = AB = \sqrt{(0-30)^2 - (0-0)^2} = \sqrt{ (-30)^2} = 30$.
and that cant be right since one of the sides is already placed on the axis and its not a right triangle.
Who said it was a right triangle?
$a^2 + b^2 = 10^2 + 20^2 = 100 + 400 = 500$ but $c^2 = 30^2 = 900$ and $500 \ne 900$. It isn't a right triangle.
Is there a formula I can plug into my program that will produce point C, given that I place A and B on x or y axis and will work with any triangle?
So if $A= (0,0)$ and $B= (c,0)$ then $C = (x,y)$ where
$b^2 = AC^2 = x^2 +y^2$
$a^2 = BC^2 = (x-c)^2 + y^2$
So $a^2 - b^2 = (x-c)^2 - x^2$ or
$a^2 - b^2 = x^2 - 2cx + c^2 - y^2 = -2cx + c^2$ or
$x = \frac {c^2 + b^2 -a^2}{2c}$
And so $x^2 +y^2 = b^2$ so
$y = \sqrt{ b^2 - x^2}$
Plugging in $a = 10; b=20; c= 30$ we get
$x =\frac {c^2 + b^2 -a^2}{2c}= \frac {30^2 + 20^2 -10^2}{2*30}= \frac {900+ 400 - 100}{60} = \frac {1200}{60} = 20$
And $x =\sqrt{ b^2 - x^2}= \sqrt {20^2 - 20^2} = 0$.
So $C = (20, 0)$
For a more proper triangle sa $a = 20; b= 15; c=25$ (an actual right triangle.
You get $A=(0,0)$ and $B = (25,0)$ and $C = (x,y)$ where
$x = \frac {c^2 + b^2 -a^2}{2c}= \frac {25^2 + 15^2-20^2}{50}= 9 $
and
$y = \sqrt{ b^2 - x^2}= \sqrt{15^2 - 9^2} = 12$
So $C = (9,12)$.
======
Now for an example where that fails: Say $a = 20; b=30; c = 60$. That's impossible because $a+b < c$. No such triangle exists.
If $A=(0,0)$ and $B=(60,0)$ then $C = (x,y)$ with
$x = \frac {c^2 + b^2 -a^2}{2c}= \frac {60^2 + 30^2-20^2}{60}= 10\sqrt{41}$
and
$y = \sqrt{ b^2 - x^2}= \sqrt{20^2 - (10\sqrt{41}^2} = \sqrt{400-410} = \sqrt{-10}$
So $C = (10\sqrt{41},\sqrt{-10})$ is not possible.