How to plot a triangle with the user's measurments?

6 ビュー (過去 30 日間)
Samy Ben Thabet
Samy Ben Thabet 2018 年 10 月 10 日
回答済み: gonzalo Mier 2018 年 10 月 10 日
Hey I am trying to plot a triangle with the user's measurements but I can't figure it out. Here is what I tried but it doesn't work.
elseif strcmp(h, 'triangle') a=input('The length of the first side is (m):'); b=input('The length of the second side is (m):'); c=input('The length of the third side is (m):'); plot([0 0],[b 0],[b a],[a c],'r','LineWidth',3) end
  1 件のコメント
jonas
jonas 2018 年 10 月 10 日
編集済み: jonas 2018 年 10 月 10 日
EDIT 3:
The problem is that you cannot build a triangle of off any three sides. There are some constraints, and it seems I am too tired to formulate them right now. At the very least the sum of two sides must be greater than the third, as can be understsood from the "very thin" triangle. In fact, that is probably the only one, but you can make at least four mirrored triangles out of any three sides even if that condition is satisfied :)

サインインしてコメントする。

採用された回答

gonzalo Mier
gonzalo Mier 2018 年 10 月 10 日
Just try:
ang = acos((a^2+b^2-c^2)/(2*a*b))
if(isreal(ang))
plot([0,a,b*cos(ang),0],[0,0,b*sin(ang),0])
end
I'm just using the cosene theorem.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by