计算角度利用反正切注意斜率存在的条件,X不能为0,先要剔除再坐标中上的情况,在分类讨论计算实际的角度,范围0~2PI
p0 = pl.Coordinate(0) p1 = pl.Coordinate(1) Dim v As Variant, lth As Double v = Array(p1(0) - p0(0), p1(1) - p0(1)) Dim ang As Double, sp(0 To 2) As Double ang = Atn(v(1) / v(0)) * 180# / (4 * Math.Atn(1)) If v(0) = 0# Then If v(1) > 0 Then ang = 90 Else ang = 270 'y轴 Else If v(1) = 0# Then If v(0) > 0 Then ang = 0# Else ang = 180 'x轴 Else If v(0) > 0 Then If v(1) > 0 Then ang = ang '第1象限 Else ang = ang + 360 '第4象限 End If Else If v(1) > 0 Then ang = ang + 180 '第2象限 Else ang = ang + 180 '第3象限 End If End If End If End If sp(0) = p1(0): sp(1) = p1(1): sp(2) = 0# With ThisDrawing.ModelSpace.AddText(ang, sp, 20) .Rotation = ang * (4 * Math.Atn(1)) / 180# .color = 3 End With