천문 계산에 필요한 수학 함수를 모아놓은 소스코드입니다.
비주얼베이직 6 또는 MS오피스 2000이상의 VBA에서 쓸 수 있습니다.
이 소스코드에는 삼각함수, 삼각함수의 역함수, 상용로그 계산 함수가 포함되어 있습니다.
앞으로 이 게시판에 올라올 천문 계산 프로그램의 코드에 종종 사용됩니다.
각각의 함수에 대한 설명은 추후 올리도록 하겠습니다.
[소스코드]
'상수
Public Const pi As Double = 3.14159265358979
Public Const hpi As Double = pi / 2
Public Const RadtoDeg As Double = 180 / pi
Public Const DegtoRad As Double = pi / 180
'삼각 함수
Public Function Arcsin(ByVal X As Double) As Double
Arcsin = Atn(X / Sqr(1 - X * X))
End Function
Public Function Arccos(ByVal X As Double) As Double
If X <= -1 Then
Arccos = pi
ElseIf X < 1 And X > -1 Then
Arccos = hpi - Atn(X / Sqr(1 - X * X))
Else
Arccos = 0
End If
End Function
Public Function Sind(ByVal X As Double) As Double
Sind = Sin(X * DegtoRad)
End Function
Public Function Cosd(ByVal X As Double) As Double
Cosd = Cos(X * DegtoRad)
End Function
Public Function Tand(ByVal X As Double) As Double
Tand = Tan(X * DegtoRad)
End Function
Public Function Arcsind(ByVal X As Double) As Double
If X >= 1 Then
Arcsind = 90
ElseIf X < 1 Then
Arcsind = RadtoDeg * Atn(X / Sqr(1 - X * X))
End If
End Function
Public Function Arccosd(ByVal X As Double) As Double
If X <= -1 Then
Arccosd = 180
ElseIf X < 1 And X > -1 Then
Arccosd = 90 - RadtoDeg * Atn(X / Sqr(1 - X * X))
Else
Arccosd = 0
End If
End Function
Public Function Arctand(ByVal X As Double) As Double
Arctand = RadtoDeg * Atn(X)
End Function
Public Function Rev(ByVal X As Double) As Double
Rev = X - Int(X / 360) * 360
End Function
Public Function Arctan2(ByVal Y As Double, ByVal X As Double) As Double
If X = 0 Then
If y = 0 Then
'error
ElseIf y > 0 Then
X = hpi
Else
X = -hpi
End If
Else
If X > 0 Then
X = Atn(y / X)
ElseIf X < 0 Then
If y >= 0 Then
X = Atn(y / X) + pi
Else
X = Atn(y / X) - pi
End If
End If
End If
Arctan2 = X
End Function
Public Function Arctan2d(ByVal Y As Double, ByVal X As Double) As Double
If X = 0 Then
If y = 0 Then
'error
ElseIf y > 0 Then
X = hpi
Else
X = -hpi
End If
Else
If X > 0 Then
X = Atn(y / X)
ElseIf X < 0 Then
If y >= 0 Then
X = Atn(y / X) + pi
Else
X = Atn(y / X) - pi
End If
End If
End If
Arctan2d = X * RadtoDeg
End Function
Public Function Log10(ByVal X As Double) As Double
If X < 0 Then X = -X
Log10 = Log(X) / 2.30258509299405 ' Log(10)=2.30258509299405
End Function