好吧,我试图复制你的问题,我认为你的问题是小数点。
- Option Explicit
- Sub Example_AngleFromXAxis()
- ' This example finds the angle, in radians, between the X axis
- ' and a line defined by two points.
-
- Dim pt1(0 To 2) As Double
- Dim pt2(0 To 2) As Double
- Dim retAngle As Double
-
- pt1(0) = 2: pt1(1) = 5: pt1(2) = 0
- pt2(0) = 5: pt2(1) = 2: pt2(2) = 0
-
- ' Return the angle
- retAngle = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)
- retAngle = RtoD(retAngle)'***** added by cmdrduh
- ' Create the line for a visual reference
- '***** added by cmdrduh
- Dim intretangle As Integer
- intretangle = CInt(retAngle)
- Select Case intretangle
- Case 0
- MsgBox "0"
- Case 315
- MsgBox "315"
- End Select
-
- ' end of ***** added by cmdrduh
- Dim lineObj As AcadLine
- Set lineObj = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
- ZoomAll
-
- ' Display the angle found
- MsgBox "The angle in radians between the X axis and the line is " & retAngle, , "AngleFromXAxis Example"
-
- End Sub
- '***** added by cmdrduh
- Private Function DtoR(d As Double) ' Degrees to Radians
- Const PI = 3.14159265
- DtoR = (PI * d) / 180
- End Function
- Private Function RtoD(r As Double) ' Radians to Degrees
- Const PI = 3.14159265
- RtoD = (180 * r) / PI
- End Function
这个函数是有帮助的,我添加了选择案例部分。 我无法找到315度线,直到我使用CInt()将双精度转换为整数。 你可以做类似的事情,或者扩大你的选择案例 |