Advertisement
scorcher646

ellipse solver

Jun 18th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from blessings import Terminal
  3. import math
  4. t=Terminal()
  5. def elipse():
  6.     #asks for a,and b
  7.     print t.white("for a circle A and B need to be equal. \nin this elipse A is whatever value is in the denominator for x")
  8.     A=float(raw_input("what is A?"))
  9.     while A == 0:
  10.         A=float(raw_input ("A cannot be 0, choose another number"))
  11.     B=float(raw_input("what is B?"))
  12.     while B == 0:
  13.         B=float(raw_input ("B cannot be 0, choose another number"))
  14.     #asks for the center
  15.     print t.white("what is the center of the elipse? (H,K)")
  16.     H=float(raw_input("what is H?"))
  17.     K=float(raw_input("what is K?"))
  18.     A2=math.pow(A, 2)
  19.     B2=math.pow(B, 2)
  20.     if A2>=B2:
  21.         C2=A2-B2
  22.     else:
  23.         C2=B2-A2
  24.     C=math.sqrt(C2)
  25.     #telling the user if the eilipse is horizontal, verticle, or a circle
  26.     if A2>B2:
  27.         print t.bright_yellow("you have a horizontal elipse\n")
  28.     elif B2>A2:
  29.         print t.bright_yellow("you have a verticle elipse\n")
  30.     elif A2==B2:
  31.         print t.bright_yellow("you have a circle\n")
  32.     print t.bright_yellow("conic form")
  33.     print t.green("((X-"+str(H)+")"u"\u00B2"")/"+str(A2)+" + ((Y-"+str(K)+")"u"\u00B2""/"+str(B2)+"=1\n")
  34.     print t.bright_yellow("Y= equations:")
  35.     print t.green("top half Y="+str(K)+"+"u'\u221A'"("+str(B)+""u"\u00B2""(1-(x-"+str(H)+")"u"\u00B2""/"+str(A)+""u"\u00B2""))")
  36.     print t.green("bottom half Y="+str(K)+"-"u'\u221A'"("+str(B)+""u"\u00B2""(1-(x-"+str(H)+")"u"\u00B2""/"+str(A)+""u"\u00B2""))\n")
  37.     #defining the foci
  38.     print t.bright_yellow("Foci:")
  39.     if A2>B2:
  40.         print t.green("(" + str(H + C) + "," + str(K) + ")\nand \n(" + str(H - C) + "," + str(K) + ")\n")
  41.     elif B2>A2:
  42.         print t.green("(" + str(H) + "," + str(K + C) + ")\nand \n(" + str(H) + "," + str(K - C) + ")\n")
  43.     elif A2==B2:
  44.         print t.green("none, this is a circle\n")
  45.     #defining the Vertexes and endpoints
  46.     if A2>=B2:
  47.         print t.bright_yellow("Vertices")
  48.         print t.green("(" + str(H + A) + "," + str(K) + ")\nand \n(" + str(H - A) + "," + str(K) + ") \n")
  49.         print t.bright_yellow("Endpoints")
  50.         print t.green("(" + str(H) + "," + str(K+B) + ")\nand\n(" + str(H) + "," + str(K-B) + ")\n")
  51.     else:
  52.         print t.bright_yellow("Vertices")
  53.         print t.green("(" + str(H) + "," + str(K+B) + ")\nand \n(" + str(H) + "," + str(K-B) +") \n")
  54.         print t.bright_yellow("Endpoints")
  55.         print t.green("(" + str(H+A) + "," + str(K) + ") \nand \n(" + str(H-A) + "," + str(K) + ")\n")
  56. elipse()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement