Support Forums
Mighty Geometry Helper v1.0 - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32)
+---- Thread: Mighty Geometry Helper v1.0 (/showthread.php?tid=3334)



Mighty Geometry Helper v1.0 - uber1337 - 12-05-2009

Its called the Geometry "Helper" because I couldn't figure out how to find the orthocenter of a triangle using python. It solves everything up to the algebra part, that's where the human comes in. This is kinda experimental because I haven't tested everything out but so far it has 5 features.

Notes:
  • Finds the slope of a line
  • Can tell if a line is perpendicular or parallel to another
  • Finds the orthocenter of a triangle(kinda)
  • Can tell if a triangle is a right triangle
  • Finds the midpoint of a line
  • If you find bugs please tell me
  • If you know how to use algebra in python please tell me
  • It is a little sloppy, just thought that today's challenge would lead to the ease of tomorrow's geometry homework
Please help me with the bugs I have already found

Known Bugs:
  • When finding the slope sometimes it will spit out a zero instead of a fraction or a decimal
  • Has error's in finding slope when zero's are involved(It says "Cannot divide by 0" even when I solve it without having to divide by 0)

If you have any suggestions for the next version, please tell me
P.SBig Grinon't run this in the IDLE unless you want a black window popping up every two seconds
Code:
import os
import platform
def clearer():
    systemver=platform.release()
    if systemver=='XP':
        os.system("cls")
    elif systemver=='Vista':
        os.system("clear")
    else:
        os.system("clear")
def menu():
    print 'To find the slope of a line, press:1'
    print 'To see if a line is perpendicular or parallel to another, press:2'
    print 'To find the orthocenter of a triangle, press: 3'
    print 'To see if a triangle is a right triangle, press: 4'
    print 'To find the midpoint of a line, press: 5'
    x = int(raw_input("What do you want to do?: "))
    clearer()
    if x==1:
        slope()
    if x==2:
        paraperp()
    if x==3:
        ortho()
    if x==4:
        right()
    if x==5:
        mid()
    if x > 4:
        print 'Please pick a number between 1 and 4'
        raw_input('Press enter to continue')
        clearer()
        menu()
    if x < 1:
        print 'Please pick a number between 1 and 4'
        raw_input('Press enter to continue')
        clearer()
        menu()
def slope(): #Add error handling
    x1 = int(raw_input("What is the first x coordinate?:"))
    clearer()
    x2 = int(raw_input("What is the second x coordinate?:"))
    clearer()
    y1 = int(raw_input("What is the first y coordinate?:"))
    clearer()
    y2 = int(raw_input("What is the second y coordinate?:"))
    clearer()
    print 'Solving.....'
    print (y2 - y1) / (x2 - x1)
    raw_input('Press enter to continue')
    clearer()
    print 'To return to the menu, press:1'
    print 'To find another slope, press:2'
    x = int(raw_input("What would you like to do?:"))
    clearer()
    if x==1:
        menu()
    if x==2:
        slope()
def paraperp():
    print 'If you have not found your two slopes, press: 1'
    print 'If you have already found your two slopes, press: Enter'
    z = raw_input("What would you like to do?:")
    if z==1:
        clearer()
        slope()
    clearer()
    print 'If one of your slopes are in decimal or fraction form, press:1'
    print 'If not, press: 2'
    a = input('What would you like to do')
    clearer()
    if a==1:
        perp()
    if a==2:
        perpa()
def perp():
    q = int(raw_input('What is the numerator of the fraction?:'))
    w = int(raw_input('What is the denominator of the fraction?:'))
    e = int(raw_input('What is the second slope?:'))
    r = q / w
    if r.denominator==-(e.numerator):
        print 'The lines are perpendicular'
        raw_input('Press enter to continue')
        print 'To return to the main menu, press:1'
        print 'To see if a line is perpendicular or parallel to another, press:2'
        v = int(raw_input("What would you like to do?:"))
        clearer()
        if v==1:
            menu()
        if v==2:
            paraperp()
    if r.numerator==-(e.denominator):
        print 'The lines are perpendicular'
        raw_input('Press enter to continue')
        print 'To return to the main menu, press:1'
        print 'To see if a line is perpendicular or parallel to another, press:2'
        v = int(raw_input("What would you like to do?:"))
        clearer()
        if v==1:
            menu()
        if v==2:
            paraperp()
    else:
        print 'The lines are not perpendicular'
        raw_input('Press enter to continue')
        print 'To return to the main menu, press:1'
        print 'To see if a line is perpendicular or parallel to another, press:2'
        v = int(raw_input("What would you like to do?:"))
        clearer()
        if v==1:
            menu()
        if v==2:
            paraperp()
def perpa():
    x = int(raw_input("What is the first slope?:"))
    clearer()
    y = int(raw_input("What is the second slope?:"))
    clearer()
    print 'solving......'
    if x==y:
        print 'The lines are parallel'
        raw_input('Press enter to continue')
        clearer()
        print 'To return to the main menu, press:1'
        print 'To see if a line is perpendicular or parallel to another, press:2'
        v = int(raw_input("What would you like to do?:"))
        clearer()
        if v==1:
            menu()
        if v==2:
            paraperp()
    if not x==y:
        print 'The lines are not perpendicular or parallel'
        raw_input('Press enter to continue')
        print 'To return to the main menu, press:1'
        print 'To see if a line is perpendicular or parallel to another, press:2'
        v = int(raw_input("What would you like to do?:"))
        clearer()
        if v==1:
            menu()
        if v==2:
            paraperp()
def ortho():# First point is a,b 2nd is c,d third is e,f
    a = int(raw_input("What is the x coordinate of the first point?:"))# let coords a,b = point A
    clearer()
    b = int(raw_input("What is the y coordinate of the first point?:"))
    clearer()
    c = int(raw_input("What is the x coordinate of the second point?:"))# let coords c,d = point B
    clearer()
    d = int(raw_input("What is the y coordinate of the second point?:"))
    clearer()
    e = int(raw_input("What is the x coordinate of the third point?:"))# let coords e,f = point C
    clearer()
    f = int(raw_input("What is the y coordinate of the third point?:"))
    clearer()
    g = (d - b) / (c - a)#slope of line AB
    h = (f - b) / (e - a)#slope of line BC
    i = (f - d) / (e - c)#slope of line AC
    #begin defining midpoints
    j = (a + c) / 2# x,y of midpoint of line AB
    k = (b + d) / 2
    l = (c + e) / 2#x,y of midpoint of line BC
    m = (d + f) / 2
    n = (e + a) / 2#x,y of midpoint of line AC
    o = (f + b) / 2
    p = (m - b) / (l - a) # Slope of A and midpoint of BC
    q = (o - d) / (n - c) # Slope of B and midpoint of AC
    print 'This is as far as I can take you my friend, as I can not do algebra, but I will show you the path to knowledge'
    print 'Let the first point you gave me = A'
    print 'Let the second point you gave me = B'
    print 'Let the third point you gave me = C'
    print 'Let the midpoint of BC = M'
    print 'Let the midpoint of AC = N'
    raw_input('Write this information down, then press enter')
    clearer()
    print 'The slope of AM is:'
    print p
    print 'The slope of BN is:'
    print q
    print 'Use the equation y=mx+b, I will break this down for you, the equation is:'
    print b
    print '='
    print p
    print a
    print '+ b'
    print 'Your jobs is to solve for b, then the you have the equation of AM'
    raw_input('Write this information down, then press enter')
    clearer()
    print 'Now use y=mx+b to find the equation for BN'
    print d
    print '='
    print q
    print c
    print '+ b'
    print 'Again, solve for b, then you have the equation for AM and BN'
    raw_input('Write this information down, then press enter')
    clearer()
    print 'Finally, to find the x,y of the orthocenter'
    print 'You write both equations equalling each other without the "y"(ex: mx+b=mx+b)'
    print 'That solved for x, now for y:'
    print 'Use one of your equations(doesnt matter which one) and plug in the x coordinate found in the last step to find y.'
    raw_input('You are done, press enter to continue')
    clearer()
    print 'To return to the main menu, press:1'
    print 'To find another orthocenter, press:2'
    v = int(raw_input("What would you like to do?:"))
    clearer()
    if v==1:
        menu()
    if v==2:
        ortho()
def mid():
    x1 = int(raw_input("What is the first x coordinate?:"))
    clearer()
    x2 = int(raw_input("What is the second x coordinate?:"))
    clearer()
    y1 = int(raw_input("What is the first y coordinate?:"))
    clearer()
    y2 = int(raw_input("What is the second y coordinate?:"))
    clearer()
    print 'Solving.....'
    x = (x1 + x2) / 2
    y = (y1 + y2) / 2
    print 'The x coordinate is:'
    print x
    print 'The y coordinate is'
    print y
    print 'To return to the main menu, press:1'
    print 'To find another midpoint, press:2'
    v = int(raw_input("What would you like to do?:"))
    clearer()
    if v==1:
        menu()
    if v==2:
        mid()
def right():
    a = int(raw_input("What is the x coordinate of the first point?:"))# let coords a,b = point A
    clearer()
    b = int(raw_input("What is the y coordinate of the first point?:"))
    clearer()
    c = int(raw_input("What is the x coordinate of the second point?:"))# let coords c,d = point B
    clearer()
    d = int(raw_input("What is the y coordinate of the second point?:"))
    clearer()
    e = int(raw_input("What is the x coordinate of the third point?:"))# let coords e,f = point C
    clearer()
    f = int(raw_input("What is the y coordinate of the third point?:"))
    clearer()
    g = (d - b) / (c - a)#slope of line AB
    h = (f - b) / (e - a)#slope of line BC
    i = (f - d) / (e - c)#slope of line AC
    if g.denominator==-(h.numerator):#GH
        print 'The triangle is a right triangle'
        raw_input('Press enter to continue')
        print 'To return to the main menu, press:1'
        print 'To see if a triangle is a right triangle, press:2'
        v = int(raw_input("What would you like to do?:"))
        clearer()
        if v==1:
            menu()
        if v==2:
            right()
    if g.numerator==-(h.denominator):
        print 'The triangle is a right triangle'
        raw_input('Press enter to continue')
        print 'To return to the main menu, press:1'
        print 'To see if a triangle is a right triangle, press:2'
        v = int(raw_input("What would you like to do?:"))
        clearer()
        if v==1:
            menu()
        if v==2:
            right()
    if g.denominator==-(i.numerator):#GI
        print 'The triangle is a right triangle'
        raw_input('Press enter to continue')
        print 'To return to the main menu, press:1'
        print 'To see if a triangle is a right triangle, press:2'
        v = int(raw_input("What would you like to do?:"))
        clearer()
        if v==1:
            menu()
        if v==2:
            right()
    if g.numerator==-(i.denominator):
        print 'The triangle is a right triangle'
        raw_input('Press enter to continue')
        print 'To return to the main menu, press:1'
        print 'To see if a triangle is a right triangle, press:2'
        v = int(raw_input("What would you like to do?:"))
        clearer()
        if v==1:
            menu()
        if v==2:
            right()
    if h.denominator==-(i.numerator):#HI
        print 'The triangle is a right triangle'
        raw_input('Press enter to continue')
        print 'To return to the main menu, press:1'
        print 'To see if a triangle is a right triangle, press:2'
        v = int(raw_input("What would you like to do?:"))
        clearer()
        if v==1:
            menu()
        if v==2:
            right()
    if h.numerator==-(i.denominator):
        print 'The triangle is a right triangle'
        raw_input('Press enter to continue')
        print 'To return to the main menu, press:1'
        print 'To see if a triangle is a right triangle, press:2'
        v = int(raw_input("What would you like to do?:"))
        clearer()
        if v==1:
            menu()
        if v==2:
            right()
    else:
        print 'The triangle is not a right triangle'
        raw_input('Press enter to continue')
        print 'To return to the main menu, press:1'
        print 'To see if a triangle is a right triangle, press:2'
        v = int(raw_input("What would you like to do?:"))
        clearer()
        if v==1:
            menu()
        if v==2:
            right()
menu()



RE: Mighty Geometry Helper v1.0 - nevets04 - 12-05-2009

Looks good, only think I would change is use float instead of int.
I was working on something similar, you beat me to it, so here what I had(This isnt finished, but no use in finishing it now Big Grin)
Code:
class math:
    def add(self,a,b): print a + b
    def sub(self,a,b): print a - b
    def mul(self,a,b): print a * b
    def div(self,a,b): print a / b
    def slope(self,a,b,c,d): print (a - b) / (c - d)
    def triangle(self,b,h): print 0.5*b*h
    def rectangle(self,b,h): print b*h
    def circle(self,r): print 3.141592*(r*r)
math = math()
def area():
    print "1) Triangle"
    print "2) Rectangle"
    print "3) Trapazoid"
    print "4) Rhombus"
    print "5) Circle"
    e = int(raw_input("What do you want to do?: "))
    if e == 1: math.triangle(float(raw_input("Base: ")), float(raw_input("Hight: ")))
    elif e == 2: math.rectangle(float(raw_input("Lengh: ")), float(raw_input("Width: ")))
    elif e == 5: math.circle(float(raw_input("Radius: ")))
    else:
        print "Please choose a valid option"
        raw_input("Press enter to continue...")    
    menu()
def slope(): math.slope(float(raw_input("First y: ")),float(raw_input("Second y: ")),float(raw_input("First x: ")),float(raw_input("Second x: ")))
def sim():
    print "1) Add"
    print "2) Subtract"
    print "3) Multiply"    
    print "4) Divide"
    c = int(raw_input("what do you want to do?: "))
    if c == 1: math.add(float(raw_input("First Number: ")),float(raw_input("Second Number: ")))
    elif c == 2: math.sub(float(raw_input("First Number: ")),float(raw_input("Second Number: ")))
    elif c == 3: math.mul(float(raw_input("First Number: ")),float(raw_input("Second Number: ")))
    elif c == 4: math.div(float(raw_input("First Number: ")),float(raw_input("Second Number: ")))
    else:
        print "Please choose a valid option"
        raw_input("Press enter to continue...")    
    menu()
def adv():
    print "1) Slope Finder"
    print "2) Area Finder"
    d = int(raw_input("What do you want to do?: "))
    if d == 1: slope()
    elif d == 2: area()
    else:
        print "Please choose a valid option"
        raw_input("Press enter to continue...")
    menu()    
def menu():
    print "1) Simple Calculator"
    print "2) Advanced calculators"    
    a = int(raw_input("what do you want to do?: "))
    if a == 1: sim()
    elif a == 2: adv()
    else:
        print "Please choose a valid option"
        raw_input("Press enter to continue...")
        menu()
menu()



RE: Mighty Geometry Helper v1.0 - uber1337 - 12-05-2009

(12-05-2009, 01:01 AM)nevets04 Wrote: Looks good, only think I would change is use float instead of int.
I was working on something similar, you beat me to it, so here what I had(This isnt finished, but no use in finishing it now Big Grin)
Code:
class math:
    def add(self,a,b): print a + b
    def sub(self,a,b): print a - b
    def mul(self,a,b): print a * b
    def div(self,a,b): print a / b
    def slope(self,a,b,c,d): print (a - b) / (c - d)
    def triangle(self,b,h): print 0.5*b*h
    def rectangle(self,b,h): print b*h
    def circle(self,r): print 3.141592*(r*r)
math = math()
def area():
    print "1) Triangle"
    print "2) Rectangle"
    print "3) Trapazoid"
    print "4) Rhombus"
    print "5) Circle"
    e = int(raw_input("What do you want to do?: "))
    if e == 1: math.triangle(float(raw_input("Base: ")), float(raw_input("Hight: ")))
    elif e == 2: math.rectangle(float(raw_input("Lengh: ")), float(raw_input("Width: ")))
    elif e == 5: math.circle(float(raw_input("Radius: ")))
    else:
        print "Please choose a valid option"
        raw_input("Press enter to continue...")    
    menu()
def slope(): math.slope(float(raw_input("First y: ")),float(raw_input("Second y: ")),float(raw_input("First x: ")),float(raw_input("Second x: ")))
def sim():
    print "1) Add"
    print "2) Subtract"
    print "3) Multiply"    
    print "4) Divide"
    c = int(raw_input("what do you want to do?: "))
    if c == 1: math.add(float(raw_input("First Number: ")),float(raw_input("Second Number: ")))
    elif c == 2: math.sub(float(raw_input("First Number: ")),float(raw_input("Second Number: ")))
    elif c == 3: math.mul(float(raw_input("First Number: ")),float(raw_input("Second Number: ")))
    elif c == 4: math.div(float(raw_input("First Number: ")),float(raw_input("Second Number: ")))
    else:
        print "Please choose a valid option"
        raw_input("Press enter to continue...")    
    menu()
def adv():
    print "1) Slope Finder"
    print "2) Area Finder"
    d = int(raw_input("What do you want to do?: "))
    if d == 1: slope()
    elif d == 2: area()
    else:
        print "Please choose a valid option"
        raw_input("Press enter to continue...")
    menu()    
def menu():
    print "1) Simple Calculator"
    print "2) Advanced calculators"    
    a = int(raw_input("what do you want to do?: "))
    if a == 1: sim()
    elif a == 2: adv()
    else:
        print "Please choose a valid option"
        raw_input("Press enter to continue...")
        menu()
menu()
What exactly does that change? Will using float make the output a decimal instead of a rounded answer? And for some things I can't use float,
Ex. For perpendicular lines I need int for the .denominator and .numerator attributes which float doesn't have.


RE: Mighty Geometry Helper v1.0 - nevets04 - 12-05-2009

float will give more exact answers when dividing. Look:
Code:
>>> x = float(2)
>>> y = float(3)
>>> x/y
0.66666666666666663
>>> x = int(2)
>>> y = int(3)
>>> x/y
0