Inaccuracy of .AnglefromAxis method | angle by two points

Inaccuracy of .AnglefromAxis method | angle by two points

Anonymous
Not applicable
1,467 Views
2 Replies
Message 1 of 3

Inaccuracy of .AnglefromAxis method | angle by two points

Anonymous
Not applicable

Hi, I am drawing a line using two known point coords.

p1(5411906,88685 | 5813796,25171)

p2(5411721,72968|5813830,60112)

Then I calculate the angle of the line using .AnglefromAxis method.

Somehow there is an inaccuracy between the angle given by the properties window by AutoCAD[349.4902603] (Picture) and the angle calculated [349,362793485571 ]. This is crucial for my main program, so do I have to deal with this inaccuracy or is there a mistake in logic ?

I am thankful for any ideas.

 

Sub angle()
Dim angle As Double
Dim p1(2) As Double
Dim p2(2) As Double
p1(0) = 5411906.88685
p1(1) = 5813796.25171
p2(0) =5411721.72968
p2(1) =5813830.60112
angle = ThisDrawing.Utility.AngleFromXAxis(p1, p2)
angle = angle * 180 / 3.xxx-xxxxxxxx
Debug.Print angle
ThisDrawing.SendCommand "line" & vbCr & "5411906.88685,5813796.25171" & vbCr & "
5411721.72968,5813830.60112" & vbCr & vbCr
End Sub
properties.PNG
0 Likes
Accepted solutions (1)
1,468 Views
2 Replies
Replies (2)
Message 2 of 3

Norman_Yuan
Mentor
Mentor
Accepted solution

Are you serious? Or are you using "FAKE" AutoCAD? Kidding.

As programmer myself, I can imagine how difficult to write code to deliberately generate "inaccurate" result for a simple math calculation. 

 

Anyway, I cannot reproduce the inaccuracy as you described with following code:

Option Explicit

Public Sub angle()

    Dim angle As Double
    Dim p1(2) As Double
    Dim p2(2) As Double
    
    p1(0) = 5411906.88685
    p1(1) = 5813796.25171
    p2(0) = 5411721.72968
    p2(1) = 5813830.60112
    
    angle = ThisDrawing.Utility.AngleFromXAxis(p1, p2)
    angle = angle * 180 / 3.1415926
    MsgBox angle

    Dim line As AcadLine
    Set line = ThisDrawing.ModelSpace.AddLine(p1, p2)
    line.Update
    MsgBox line.angle * 180 / 3.1415926

    '' This would result in the same angle
    ThisDrawing.SendCommand _
        "line" & vbCr & _
        "5411906.88685,5813796.25171" & vbCr & _
        "5411721.72968,5813830.60112" & vbCr & vbCr
    
End Sub

By the way, When post code, please use the button "</>" on toolbar above the input window, so that the code would be easier to read.

 

It is strange you hide the PI value you used as "3.xxx-xxxx" in your code. So, my guess would be that the only reason your code's calculation is wrong is because you used WRONG PI value, which should be 3.1415926...

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

Anonymous
Not applicable

I just tried to reproduce the inaccuracy at home (Acad2017), no inaccuracy in sight. At work I am using Acad2015, shouldn't make a difference, right? I'll try to reproduce again at work tomorrow.

Thanks for the advice about posting code right, I'll try to use it next time.

By using Ctrl + C and Ctrl + V somehow my "pi" got transformed from 3,xxx-xxxxxxxx to 3.xxx-xxxxxxxx.

0 Likes