Results 1 to 11 of 11

Thread: [RESOLVED] Angles of Lines Tangent to Circle

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Resolved [RESOLVED] Angles of Lines Tangent to Circle

    Hi all.

    Anyone here able help me out?

    I need to find the angles of the two lines that are tangent to a circle and pass through the origin. Problem is I need the angles to be an angular direction ie 0 to 2pi from the origin which is obviously be dependant on the location of the circle relative to the origin.

    I can work out the angles of the lines (0 to +-pi) but not the angular directions.

    Guess I have to put in quite a few ifs and buts about the positions of the tangent points.
    Last edited by sgrya1; Oct 2nd, 2006 at 06:38 PM.

  2. #2
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Angles of Lines Tangent to Circle

    The angles are

    Theta1 = Atn [(ab + rSqr(K)) / M]
    Theta2 = Atn [(ab - rSqr(K)) / M]

    where

    K = a2 + b2 - r2
    M = a2 - r2

    r is the radius of the circle and (a,b) the coordinates of its center.

    Because the VB Atn function returns values between +Pi/2 and -Pi/2 you must indeed add some ifs for the various cases.

    First, to avoid divisions by zero, the case a = r must be dealt with. In this case, Theta1 = Pi/2 and Theta 2 turns out to be an expression of the type 0/0 which can be determined by calculating the limit:

    Theta2 = lim(a -> r) Atn[(ab - rSqr(K)) / M] = b/r - r/b

    Now:

    If a>0 and b>0, we're done.
    If a>0 and b<0, report the angles as 2*Pi + Theta1 and 2*Pi + Theta2
    If a<0 the angles are Pi - Theta1 and Pi - Theta2 regardless of the sign of b.

    Check this out carefully, I can't guarantee there aren't any mistakes.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Angles of Lines Tangent to Circle

    Thanks krtxmrtz ,

    I had to change the if statement for
    If a<0 the angles are Pi - Theta1 and Pi - Theta2
    to
    If a<0 the angles are Pi + Theta1 and Pi + Theta2

    Can you or someone help me debug it a bit further please. Out of my league. Didn't even have your equations correct.

    Attached is a simple code with graphical output which should help. I'm still having problems with :
    for r = .5 and
    a = 0.5, b = 1
    a = 0, b = 1
    a = -0.5, b = 1
    and
    a = 0.5, b = -1
    a = 0, b = -1
    a = - 0.5, b = -1
    Attached Files Attached Files
    Last edited by sgrya1; Oct 3rd, 2006 at 08:46 AM.

  4. #4
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Angles of Lines Tangent to Circle

    I know it's a bit messy but I think it's working, check it out. Incidentally I found a few mistakes in my derivation above.

    The phrase you referred to in my signature is not latin but portuguese and I came across it in a Brazilian web site. It means, "he who can't forgive is destroying the bridge over which he himself must cross". I think it's wise.
    Attached Files Attached Files
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Angles of Lines Tangent to Circle

    OMG. Who was that man?
    I can't thank you enough for that.
    You've even given coding advice.
    There's no way I would have gotten past that one.

  6. #6
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Angles of Lines Tangent to Circle

    Quote Originally Posted by sgrya1
    OMG. Who was that man?
    I can't thank you enough for that.
    You've even given coding advice.
    There's no way I would have gotten past that one.
    Well, then I'd appreciate some credit (-> "rate this post")
    At any rate, I'm sorry I didn't have much time to make it tidier, probably it can all be arranged in a much simpler fashion.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: [RESOLVED] Angles of Lines Tangent to Circle

    Sorry, didn't realise I could do that.
    Make it tidier? Man, that is a one liner and crystal clear compared to what I have put together. You'd be horrified. Self taught and obvious. Thank god computers these days are fast enough not to care about my coding deficiencies.
    Thanks again. Wish I could repay the favour but sadly seems unlikely.
    Last edited by sgrya1; Oct 3rd, 2006 at 05:27 PM.

  8. #8
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: [RESOLVED] Angles of Lines Tangent to Circle

    I think this is a clearer approach (not too different, though):

    Let K1 and K2 the tangents of the 2 angles, i.e. the slopes of the tangent lines:

    K1 = [ab + r*Sqr(a2 + b2 - r2)] / (a2 - r2)

    K2 = [ab - r*Sqr(a2 + b2 - r2)] / (a2 - r2)

    The idea is to calculate the coordinates of the two points of tangency and from these derive the angles (but you don't need the angles for the plot, once you have the coordinates).

    Now, first of all consider the special case a=r. Now K2 tends to infinity and

    K1 = 0.5*(b/r - r/b) if a>0
    K1 = -0.5*(b/r - r/b) if a<0

    For K2 -> infinity the coordinates are:
    x = 0
    y = b

    For the case K1 with a=r and all the other cases (a <> r) the coordinates are calculated from K:

    x = (a + bK1)
    y = K1x

    x = (a + bK2)
    y = K2x
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  9. #9
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: [RESOLVED] Angles of Lines Tangent to Circle

    ...and I have finally dug out this code snippet from the mess of my hard disk.
    VB Code:
    1. Function angvec(X, Y, Success) As Single
    2. 'Returns the angle from 0 to 2*Pi between the x axis
    3. 'and the vector of coordinates X,Y
    4. 'Pi has been declared elsewhere
    5.  
    6.     Success= False
    7.     If X = 0 And Y = 0 Then Exit Function
    8.  
    9.     Success = True
    10.  
    11.     If X = 0 Then
    12.         If Y > 0 Then
    13.             angvec = Pi / 2
    14.         ElseIf Y < 0 Then
    15.             angvec = 3 * Pi / 2
    16.         End If
    17.         Exit Function
    18.     Else
    19.         angvec = Atn(Y / X)
    20.         If X > 0 And Y < 0 Then
    21.             angvec = 2 * Pi + angvec
    22.         ElseIf X < 0 Then
    23.             angvec = Pi + angvec
    24.         End If
    25.     End If
    26. End Function
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: [RESOLVED] Angles of Lines Tangent to Circle

    krtxmrtz,

    Would you be able to have a last look at the tangent program. I had a good go at updating it such that the tangent points are calculated according to the method you suggested out but failed at it so it's still pretty much in the original state.

    Still have a problem that when A=0 (or more particularly when the circle crosses the y axis) I get one angle reporting incorrectly. I can't get my head around it.

    Would you please help tweak it for me?
    Attached Files Attached Files

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: [RESOLVED] Angles of Lines Tangent to Circle

    Wasn't that difficult and should have given it some more thought. Thanks again.
    VB Code:
    1. k = A * A + B * B - r * r
    2.         M = A * A - r * r
    3.         If Abs(A) = Abs(r) Then
    4.             If B > 0 Then
    5.                 angle1 = 0.5 * pi
    6.             Else
    7.                 angle1 = 1.5 * pi
    8.             End If
    9.             angle2 = Math.Atn(0.5 * (B / r - r / B))
    10.             If A > 0 And B < 0 Then
    11.                 angle2 = 2 * pi + angle2
    12.             ElseIf A < 0 Then
    13.                 angle2 = pi - angle2
    14.             End If
    15.         Else
    16.             angle1 = Math.Atn((A * B + r * Sqr(k)) / M)
    17.             angle2 = Math.Atn((A * B - r * Sqr(k)) / M)
    18.             If A - r < 0 And A + r > 0 And B > 0 Then
    19.                 angle1 = pi + angle1
    20.             ElseIf A - r < 0 And A + r > 0 And B < 0 Then
    21.                 angle1 = 2 * pi + angle1
    22.                 angle2 = pi + angle2
    23.             ElseIf A > 0 And B < 0 Then
    24.                 angle1 = 2 * pi + angle1
    25.                 angle2 = 2 * pi + angle2
    26.             ElseIf A < 0 Then
    27.                 angle1 = pi + angle1
    28.                 angle2 = pi + angle2
    29.             End If
    30.         End If

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