|
Private Sub Command1_Click()
Dim a, b, c, x, u1, u2, w1, w2 As Double
a = Val(Txt_a.Text)
b = Val(Txt_b.Text)
c = Val(Txt_c.Text)
x = Atn(b / a)
u1 = ArcCos(c / Sqr(a ^ 2 + b ^ 2)) + x
u2 = (2 * 3.14159265358979 - ArcCos(c / Sqr(a ^ 2 + b ^ 2)))
+ x
w1 = (u1 / 3.14159265358979) * 180
w2 = (u2 / 3.14159265358979) * 180
If w2 > 360 Then
w2 = w2 - 360
End If
Lbl_Answer1.Caption = Round(w1, 2)
Lbl_Answer2.Caption = Round(w2, 2)
End Sub
Public Function ArcCos(y As Double)
ArcCos = Atn(-y / Sqr(-y * y + 1)) + 2 * Atn(1)
End Function
Private Sub Command2_Click()
Txt_a.Text = ""
Txt_b.Text = ""
Txt_c.Text = ""
Lbl_Answer1.Caption = ""
Lbl_Answer2.Caption = ""
End Sub
|
Explantion
There is no
built-in function for Arc Cosine but there is one such
function for Arc Tangent
i.e Atn.
However, we can create one function for ArcCos using the
formula
ArcCos = Atn(-y / Sqr(-y * y + 1)) + 2 * Atn(1)
which is derived
from Pythagoras Theorem using a right-angled triangle.
I use the
keyword Public so that other sub procedure can make use of
this function.
For the
mathematical part, we know that we can express the equation
a cos
q +
b sinq
=c can
be expressed as Rcos(
q-x)=c
and
R=sqr(a2+b2)
and x=tan-1(b/a)
Therefore,
q=cos-1(c/R)+x,
expressed in radian.
To convert the answer to
degree, multiply it by 180 and divide it by pi (3.14159265358979)
The rest you
just have to convert them to VB codes.
There are two
possible answers between 0 and 360 degree. |