2015-07-13 165 views
0

我正在學習三角形的所有三邊的知識,它們是由用戶輸入的。我需要知道如果任何角度將等於90度 我已經查了這個數學,但很遺憾不知道如何嘗試使用它在三角形中找到直角

我正在找出用戶具有什麼樣的三角形每邊的長度

If First <> Second AndAlso Second <> Third AndAlso First <> Third Then 
    MsgBox("Triangle is scalene") 
ElseIf First = Second AndAlso Second = Third AndAlso First = Third Then 
    MsgBox("Triangle is equilateral") 
ElseIf First = Second Or Second = Third Or First = Third Then 
    MsgBox("Triangle is isosceles") 
ElseIf rightangle Then 
    MsgBox("Triangle is right angle") 
Else 
    MsgBox("UFT - Unidentified flying triangle") 
End If 

我不知道從哪裏開始,沒有形成缺乏嘗試

+2

你一定需要[trig](https://www.mathsisfun.com/algebra/trig-solving-sss-triangles.html)。 –

+0

如果你輸入的是角度,那你爲什麼不比較並檢查,如果任何值等於90? – Tushar

+0

@TusharGupta輸入變量表示邊的長度,而不是角度。 – phoog

回答

3

直角三角形,兩個短邊的平方和等於平方長邊。例如,3^2 + 4^2 = 5^2,所以邊長爲3,4,5的三角形是直角三角形。

0

,你需要做的基本輪廓:

  1. 從用戶獲取三個邊長

  2. 找到三個角度

    • 使用餘弦定律找到第一角度
    • 使用正弦律找到第二角度
    • 查找第三角度通過使用180 - (+第一第二)
  3. 檢查多少這些角度是90度,並應用所需的任何邏輯。

+0

我明白需要什麼...只是不怎麼做 – Cacoon

2

這是你需要檢查使用雙方。您可能需要對值進行四捨五入以避免浮點比較問題。

If First = Math.Sqrt(Second * Second + Third * Third) OrElse Second = Math.Sqrt(First * First + Third * Third) OrElse Third = Math.Sqrt(First * First + Second * Second) Then 
    MsgBox("Triangle is right angle") 
End If 
+0

似乎是唯一有用的給定答案,謝謝 – Cacoon

+1

但我更喜歡第一*第一=第二*第二+第三*第三 – ggrr

+0

由你決定...精度事項。 –