﻿ VB中的atn函数-vb.net_软件编程-脚本宝典

# VB中的atn函数

## VB中的atn函数

Atn函数返回一个double类型，指定一个数的反正切值。用法就是：Atn(number)。number参数是一个double或者任何有效的数值表达式。Atn函数的参数值（number）为直角三角形的两条直角边的比值（

Atn函数返回一个double类型，指定一个数的反正切值。

Atn函数的参数值（number）为直角三角形的两条直角边的比值（对边比邻边）。返回以弧度为单位的角。值的范围是-π/2和π/2之间。

Atn是Tan函数的反三角函数，Tan的参数值为角度，返回直角三角形的两边的比值。

www.2cto.com

Public Function getAngel(ByVal x1 As Long, _

ByVal y1 As Long, _

ByVal x2 As Long, _

ByVal y2 As Long) As Long

Const PI     As Double = 3.1415926

Dim judge  As Boolean

'VB中默认boolean值为False，这里如果是默认（即judge=False），结果永远等于0

judge = True

Dim Ang As Long

Select Case judge

Case x1 < x2 And y1 < y2

Ang = Atn((y2 - y1) / (x2 - x1)) * 180 / PI

Case x1 < x2 And y1 = y2

Ang = 0

Case x1 < x2 And y2 > y2

Ang = Atn((y2 - y1) / (x2 - x1)) * 180 / PI + 360

Case x1 = x2 And y1 < y2

Ang = 90

Case x1 = x2 And y1 = y2

MsgBox "两个点重复，请从新输入！"

Case x1 = x2 And y1 > y2

Ang = 270

Case x1 > x2 And y1 < y2

Ang = Atn((y2 - y1) / (x2 - x1)) * 180 / PI + 180

Case x1 > x2 And y1 = y2

Ang = 180

Case x1 > x2 And y1 > y2

Ang = Atn((y2 - y1) / (x2 - x1)) * 180 / PI + 180

End Select

getAngel = Ang

'angel = getAngel(x1, y1, x2, y2)

End Function

Private Sub Form_click()

Text1(4).Text = Format(getAngel(CDbl(Text1(0).Text), CDbl(Text1(1).Text), CDbl(Text1(2).Text), CDbl(Text1(3).Text)), "0.000 ")

End Sub

Tags：

﻿
<