0
$\begingroup$

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). I tried the solution from the other topic and it didn't work since the result produced was C(20,0) and that cant be right since one of the sides is already placed on the axis and its not 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?

Thank you.

$\endgroup$
  • 6
    $\begingroup$ There is no triangle with sides such that $a+b=c$. $\endgroup$ – AugSB Dec 18 '18 at 20:48
  • 1
    $\begingroup$ It gave you that answer because that was the correct answer. A triangle with $a= 10, b = 20, c = 30$ is not a right triangle because $10^2 + 20^2 \ne 30^2$. A triangle with side $a=10, b=20, c=30$ is not a triangle at all but an straight line segment. $\endgroup$ – fleablood Dec 18 '18 at 20:54
  • $\begingroup$ You can read up on Triangle Inequality if you want... It seems that sometimes we refer to this case as a degenerate triangle which I think of (and seems to be the common parlance) as more of a line segment than a triangle. $\endgroup$ – Mason Dec 18 '18 at 21:00
3
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Thank you. I guess it was some kind of trick question "In main(), create one instance each of the following: a Circle with a radius of 23, a Square with sides 25, and a Triangle with sides 10, 20, 30. Define all of them so that the origin (0,0) is somewhere within each object. Display the information from each object." I know that it's not a right triangle, I said that its not. $\endgroup$ – Stand Studios Dec 19 '18 at 14:27
1
$\begingroup$

Given sides a,b,and c, use the law of cosines to calculate the angle $\theta$ between a and b. then (for example), plot b as horizontal, and plot a as a directional vector, with angle $\theta.$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.