# Re: ACOS(x)与ASIN(x)的问题(三角函数)......

Posted by Honey on October 23, 1999 at 11:16:30:

In Reply to: ACOS(x)与ASIN(x)的问题(三角函数)...... posted by vb怪手 on October 22, 1999 at 12:44:59:

: 请问各位网友:
: 反三角函数ASIN(X)与ACOS(x)应如何撰写呢??????或是那有现成已写好的函数可取得...........谢谢....
可用二元搜寻法
试试看以下函数
可试着输入
s=ASin(0.5)
试试看传回值S是否为30
也可以试试其他数值
如果知道了 ACos也就不是问题了 就此省略
Public Function ASin(SValue As Double) As String
Dim Pi As Double, dX As Byte, Cen As Double
Dim dCen As Double
Cen = 90
dCen = 90
Pi = 3.14159265358979 '3238462643383279502884197
If Abs(SValue) > 1 Then
MsgBox "Sin函数值介于1到-1之间", vbOKOnly, "呆瓜"
Exit Function
End If
'Note:由于Sin(Pi/2)=1 Sin函数绝对值小于等于1 _
有对秤性 讨论值只要0~(Pi/2)即可 _
例如 Sin(U)=Sin(Pi-U) _
-Sin(U)=Sin(Pi+U) 即可表示所有角度

If SValue < 0 Then '/*角度为(Pi+k), 0 <= k<= Pi*/
dX = 180 '/*根据-Sin(U)=Sin(Pi+U)这式子 纪录位移*/
SValue = -SValue
End If

'Note:Sin函数由0~(Pi/2)为递增 可用二元搜寻法寻找值
If SValue = 1 Then
Cen = Cen + dX
ASin = CStr(Cen)
Exit Function
Else
Do While Abs(Sin(Cen * Pi / 180#) - SValue) > 1E-16 '/*允许误差值*/
Dim j As Double
dCen = dCen / 2#
If Sin(Cen * Pi / 180#) > SValue Then
Cen = Cen - dCen
Else
Cen = Cen + dCen
End If
Loop
Cen = Cen + dX
ASin = CStr(Cen)
End If

End Function

Follow Ups:

- Re: ACOS(x)与ASIN(x)的问题(三角函数)...... Honey 19:58:24 10/23/99 (0)