Results 1 to 25 of 25

Thread: Calculating the angle of a Line in a circle(resolved)

Hybrid View

  1. #1
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculating the angle of a Line in a circle

    Or swap x2 and x1 of x2>x1, and the same for y

  2. #2

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Calculating the angle of a Line in a circle

    Quote Originally Posted by dglienna
    Or swap x2 and x1 of x2>x1, and the same for y
    I tried this also and I get the same exact thing for whichever I try

  3. #3
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Calculating the angle of a Line in a circle

    VB Code:
    1. Private Function GetAngle(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long) As Double
    2.     Dim PI As Double
    3.     Dim theta As Double
    4.     Dim deltaX As Long
    5.     Dim deltaY As Long
    6.     'get angle of line in radians
    7.     'deltay/deltax = tan(angle)
    8.     deltaY = Y1 - Y2
    9.     deltaX = X2 - X1
    10.     PI = Atn(1) * 4
    11.     'adjust to our coordinate system
    12.         If deltaX = 0 Then
    13.             'fix division by zero errors
    14.             If Y1 > Y2 Then
    15.                 theta = 180
    16.             Else
    17.                 theta = 90
    18.             End If
    19.         ElseIf deltaX > 0 And deltaY >= 0 Then '1st quadrant
    20.             theta = Atn((Y1 - Y2) / (X2 - X1))
    21.         ElseIf deltaX < 0 And deltaY >= 0 Then '2nd quadrant
    22.             theta = Atn((Y1 - Y2) / (X2 - X1)) + PI
    23.         ElseIf deltaX < 0 And deltaY < 0 Then '3rd quadrant
    24.             theta = Atn((Y1 - Y2) / (X2 - X1)) + PI
    25.         ElseIf deltaX > 0 And deltaY < 0 Then '4th quadrant
    26.             theta = Atn((Y1 - Y2) / (X2 - X1)) + 2 * PI
    27.         End If
    28.    
    29.     'convert to degrees
    30.     'there are 180 degrees per PI radians
    31.     'if theta < 0 then theta =
    32.     GetAngle = theta * 180 / PI
    33. End Function

  4. #4

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Calculating the angle of a Line in a circle

    great thanks moeur

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculating the angle of a Line in a circle

    moeur, could you possible explain that? I thought that it had something to do with quadrants, but didn't want to try to guess at the answer. If not, that's ok, also. I was thinking that 0 degrees was at 9'oclock, and that was the issue. Maybe I was close.

  6. #6
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Calculating the angle of a Line in a circle(resolved)

    The problem is how the ArcTangent is defined
    -90° < Atn(x) < 90°
    for
    -infinity < x < infinity

    But that is not what we wanted so I had to adjust
    Last edited by moeur; Nov 6th, 2005 at 01:09 AM.

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculating the angle of a Line in a circle(resolved)

    Well, I wish that I could have seen an explanation, but I found this link, and it didn't help much.

    http://mathworld.wolfram.com/InverseTangent.html

    I looked up tangent, and saw the same images.

    http://mathworld.wolfram.com/Tangent.html

    I guess I don't know what I'm looking at.

    I used to know the formula to draw a circle with COS and SIN, so thought this wouldn't be too hard to grasp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width