1 | #Region "Microsoft.VisualBasic::b7ee6572f712749b8a830edf8637472b, Microsoft.VisualBasic.Core\Extensions\Math\Trigonometric\Arctan.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Module Trigonometric |
35 | ' |
36 | ' Function: Atn |
37 | ' |
38 | ' |
39 | ' /********************************************************************************/ |
40 | |
41 | #End Region |
42 | |
43 | Imports sys = System.Math |
44 | |
45 | Namespace Math |
46 | |
47 | Partial Module Trigonometric |
48 | |
49 | Const HalfPI# = PI / 2 |
50 | Const n1# = 1.0R |
51 | Const n05# = 0.5R |
52 | |
53 | ''' <summary> |
54 | ''' 通过这个参数来控制计算精度,这个参数值越大,计算精度越高 |
55 | ''' </summary> |
56 | Public AtanPrecise% = 500 |
57 | |
58 | ''' <summary> |
59 | ''' Taylor Atan |
60 | ''' </summary> |
61 | ''' <param name="x"></param> |
62 | ''' <returns></returns> |
63 | ''' <remarks>Atan测试没有问题</remarks>> |
64 | Public Function Atn(x#) As Double |
65 | If x# = 1.0 Then |
66 | Return PI / 4 |
67 | End If |
68 | If sys.Sign(x) = sys.Sign(-1) Then |
69 | Return -Atn(-x) |
70 | End If |
71 | If x > n1 Then |
72 | Return HalfPI - Atn(1 / x) |
73 | End If |
74 | If x > n05 Then |
75 | Return Atn(n1) + Atn((x - n1) / (1 + x)) |
76 | Else |
77 | Dim xPow2 As Double = x * x |
78 | Dim n__1 As Integer = AtanPrecise |
79 | Dim y As Double = 1 / (2 * n__1 + 1) |
80 | Dim i As Integer = AtanPrecise |
81 | |
82 | While i > 0 |
83 | y = (1 / (2 * n__1 - 1)) - (xPow2 * y) |
84 | i -= 1 |
85 | n__1 -= 1 |
86 | End While |
87 | |
88 | Return x * y |
89 | End If |
90 | End Function |
91 | End Module |
92 | End Namespace |