Results 1 to 6 of 6

Thread: Line and Circle Interception

  1. #1
    Join Date
    Mar 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Line and Circle Interception

    I' m making a line and circle interception program, and it's not working. What am I doing wrong? Thanks.
    from math import sqrt

    def input_values():
    def get_float(s):
    return float(input('Enter %s: ' % s))
    return (get_float('slope'), get_float('y_intercept'),
    get_float('radius'), get_float('center x'), get_float('center y'))

    def calc_intercection(slope, y_intercept, radius, center_x, center_y):
    a = 1 + slope**2
    b = -center_x + slope, y_intercept - slope*center_y
    c = center_x**2 + center_y**2 + y_intercept**2 - 2*y_intercept*center_y - radius*radius
    D = b**2 - a*c
    if D < 0:
    print('No Solutions')
    return
    x1 = (-b + sqrt(D)) /2*a
    x2 = (-b - sqrt(D)) /2*a
    print((x1, slope*x1 + y_intercept), (x2, slope*x2 + y_intercept))


    while True:
    calc_intercection(input_values())
    if input('Enter "Y" to continue: ') != 'Y': break

  2. #2
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    For sheer readability, you might want to wrap your code in [CODE] tags, it will probably help whoever takes a look at it
    Ce ne sont que des gueux


  3. #3
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    python Code:
    from math import sqrt

    def input_values():
        def get_float(s):
            return float(input('Enter %s: ' % s))
        return (get_float('slope'), get_float('y_intercept'),
                get_float('radius'), get_float('center x'), get_float('center y'))

    def calc_intercection(slope, y_intercept, radius, center_x, center_y):
        a = 1 + slope**2
        b = -center_x + slope, y_intercept - slope*center_y
        c = center_x**2 + center_y**2 + y_intercept**2 - 2*y_intercept*center_y - radius*radius
        D = b**2 - a*c
        if D < 0:
            print('No Solutions')
            return
        x1 = (-b + sqrt(D)) /2*a
        x2 = (-b - sqrt(D)) /2*a
        print((x1, slope*x1 + y_intercept), (x2, slope*x2 + y_intercept))


    while True:
        calc_intercection(input_values())
        if input('Enter "Y" to continue: ') != 'Y': break

    Wrapped in the proper tags..
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  4. #4
    Join Date
    Mar 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SO..... can any one tell me why I'm getting a error.
    Code:
    Traceback (most recent call last):
      File "C:\Users\Sylvia\Documents\Python Saves\LCI Program.py", line 23, in <module>
        calc_intersection(input_values())
    TypeError: calc_intersection() takes exactly 6 arguments (1 given)
    Last edited by VandyTech; 03-17-2011 at 01:34 AM.

  5. #5
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    I'm not a python programmer, but
    "return (get_float('slope'), get_float('y_intercept'), get_float('radius'), get_float('center x'), get_float('center y'))" looks like 1 argument to me... tried removing one nest of parentheses?

  6. #6
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    That's returning a tuple, and taking off the parentheses will make the same exact tuple.

    The problem is you're passing a single argument, as a tuple is a single thing (it just contains multiple things).

    And then after that, you have b set to a tuple as well, so you need to change that, because you can't do tuple**2.
    Last edited by i luffs yeww; 03-17-2011 at 02:47 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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