写一段VBA代码,已知两点的坐标,如何计算两点的角度
时间: 2023-03-14 22:03:35 浏览: 108
Sub CalcAngle()
Dim x1, y1, x2, y2 as Integer
Dim angle As Double
x1 = InputBox("请输入第一个点的X坐标")
y1 = InputBox("请输入第一个点的Y坐标")
x2 = InputBox("请输入第二个点的X坐标")
y2 = InputBox("请输入第二个点的Y坐标")
angle = Atan2(y2 - y1, x2 - x1) * 180 / 3.14159265
MsgBox "两点之间的角度为" & angle
End Sub
相关问题
写一段VBA代码,已知两点的坐标,如何计算两点的连线与x轴的夹角
Sub Calculate_Angle(x1 As Single, y1 As Single, x2 As Single, y2 As Single)
Dim Angle As Single
Angle = Atn(y2 - y1 / x2 - x1) * (180 / 3.14159)
MsgBox Angle
End Sub
写一段CAD vba代码,已知的多个坐标,求每个坐标与相邻坐标的角度
Sub 计算角度()
Dim x1, y1, x2, y2 As Double
Dim 角度 As Doublex1 = Cells(1, 1).Value
y1 = Cells(1, 2).Value
x2 = Cells(2, 1).Value
y2 = Cells(2, 2).Value角度 = Application.WorksheetFunction.Atan2(y2 - y1, x2 - x1)MsgBox 角度End Sub