
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Guys,
I am a beta tester for AutoCAD, but I have a problem I would like some help with. I am creating a calculator that solves the right angled triangle for my CAD students. I have programmed it in VB.NET, all you have to enter are two known quantities to get the other results. It all works ok apart from entering 'B+a' and 'C+a', with these two I am getting weird results. (see attached image)
I am using the 3,4,5 triangle to test the software. Any help would be much appreciated.
Regards,
Steve.
Here is the code I have for the application:
Imports System.String
Imports System.Math
Public Class Form1
Dim angleA As Single = 90
Dim angleB As Single
Dim angleC As Single
Dim sidea As Single
Dim sideb As Single
Dim sidec As Single
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
Controls.Add(NumericUpDown1)
End Sub
Public Function isItNullString(ByVal value) As Boolean
If value = "" Then
Return True
Else
Return False
End If
End Function
Public Sub pythagoreanTheoremThings()
If sideb = 0 Then
sideb = Math.Sqrt((sidea * sidea) - (sidec * sidec))
TextBoxSideb.Text = sideb
ElseIf sidea = 0 Then
sidea = Math.Sqrt((sideb * sideb) + (sidec * sidec))
TextBoxSidea.Text = sidea
ElseIf sidec = 0 Then
sidec = Math.Sqrt((sidea * sidea) - (sideb * sideb))
TextBoxSidec.Text = sidec
End If
End Sub
Public Sub angleSums()
If angleC = 0 And angleB <> 0 Then
angleC = 180 - angleA - angleB
TextBoxAngleC.Text = angleC
End If
If angleB = 0 And angleC <> 0 Then
angleB = 180 - angleA - angleC
TextBoxAngleB.Text = angleB
End If
End Sub
Public Sub angleBasWorkingAngle()
'Angle B and side b known, find side a
If angleB <> 0 Then
sidea = sideb / Sin(degreesToRadians(angleB))
TextBoxSidea.Text = sidea
End If
'Angle B and side c known, find side b
If angleB <> 0 And sidec <> 0 Then
sideb = sidec * Tan(degreesToRadians(angleB))
TextBoxSideb.Text = sideb
End If
End Sub
Public Sub findangleC()
If angleC = 0 Then
'cos
angleC = radiansToDegrees(Acos(sideb / sidea))
TextBoxAngleC.Text = angleC
End If
End Sub
Public Sub feedValues()
If Not isItNullString(TextBoxSideb.Text) Then
sideb = TextBoxSideb.Text
Else
sideb = 0
End If
If Not isItNullString(TextBoxSidea.Text) Then
sidea = TextBoxSidea.Text
Else
sidea = 0
End If
If Not isItNullString(TextBoxSidec.Text) Then
sidec = TextBoxSidec.Text
Else
sidec = 0
End If
If Not isItNullString(TextBoxAngleC.Text) Then
angleC = TextBoxAngleC.Text
Else
angleC = 0
End If
If Not isItNullString(TextBoxAngleB.Text) Then
angleB = TextBoxAngleB.Text
Else
angleB = 0
End If
End Sub
Public Function degreesToRadians(ByVal degrees As Double) As Double
Dim radians As Double
radians = (Math.PI * degrees) / 180
Return radians
End Function
Public Function radiansToDegrees(ByVal radians As Double) As Double
Dim degrees As Double
degrees = radians * (180 / Math.PI)
Return degrees
End Function
#Region " Calculate all Data "
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
For aaa As Integer = 0 To 2 'I just repeated this 6 times because I have a lot of processing power
'you can do it twice.
feedValues()
pythagoreanTheoremThings()
angleSums()
angleBasWorkingAngle()
findangleC()
Next
End Sub
#End Region
#Region " Clear all input boxes "
Public Sub ClearTextBox(ByVal root As Control)
For Each ctrl As Control In root.Controls
ClearTextBox(ctrl)
If TypeOf ctrl Is TextBox Then
CType(ctrl, TextBox).Text = String.Empty
End If
Next ctrl
End Sub
#End Region
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
ClearTextBox(Me)
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Solved! Go to Solution.