-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconics.py
More file actions
executable file
·212 lines (114 loc) · 3.49 KB
/
conics.py
File metadata and controls
executable file
·212 lines (114 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#*! users/avery/temp
import math
import time
import sys
import os
import matplotlib.pyplot as plt
import numpy as np
python = sys.executable
x = 50
# Basically what the program does.
#x = (p1, p1n, p1a, p1an, p1b, p1bn, p1c, p1cn)
#y = (p2, p2n, p3, p3n, p4, p4n, p5, p5n)
#y = ax^2 + hx + k
#y - k = ax^2 + hx
#y - k = a(x^2 + hx)
#h/2 = _^2
##y - k + {h/2 = _^2} = a(x^2 + hx + {h/2 = _^2})
#y - k = a(x + h)x(x + {h/2 = _^2})
#y - k = a(x + h)^2
#End
#y - k = a(x - h)^2 -/ final
print "Welcome to the Conic equation transformer!"
print "if ready type p"
user_input = raw_input(":")
if user_input=="p":
num_a = float (raw_input("a:"))
num_b = float (raw_input("b:"))
num_c = float (raw_input("c:"))
#y = ax^2 + hx + k
print ('Your form is y = %sx^2 + %sx + %s...correct? [yes/no]') % (num_a, num_b, num_c)
user_input = raw_input(":")
if user_input=="yes":
print ("Great! Here you go!")
print"=" * x
numb = (num_b / 2.0)
numb2 = (numb ** 2)
numcb = (num_c + numb2)
ts = time.sleep
num_c_2 = (0 - num_c)
ts(1)
#y - k = ax^2 + hx
print ("y %s = %sx^2 + %sx") % (num_c_2, num_a, num_b)
print"=" * x
num_a2 = (num_b / num_a)
numb = (num_a2 / 2.0)
numb2 = (numb ** 2)
numc = (0 - num_c)
numcb = (numc + numb2)
numcb_2 = ((numb2 * num_a) + num_c_2)
ts(1)
#y - k = a(x^2 + hx)
print ("y %s = %s(x^2 + %sx + %s)") % (numcb_2, num_a, num_a2, numb2)
print"=" * x
numb2_2 = (numb2 / 2.0)
num_b2 = (num_b / 2.0)
final = (num_a2 / 2.0)
ts(1)
#y - k = a(x + h)^2 final
print ("y %s = %s(x + %s)^2" ) % (numcb_2, num_a, final)
print"=" * x
vy = (numcb_2 * -1.0)
vx = (final * -1.0)
ts(1)
print ("Vertex = (%s, %s)") % (vx, vy)
print"=" * x
yfocus = (num_a + final)
ts(1)
print ("Focus = (%s, %s)") % (vx, yfocus)
print"=" * x
ts(1)
p1 = (vx + 1.0) #go over 1, and see what y equals then.
p2 = (num_a * p1**2 + num_b * p1 + num_c)
p1a = (vx + 2.0)
p3 = (num_a * p1a**2 + num_b * p1a + num_c)
p1b = (vx + 3.0)
p4 = (num_a * p1b**2 + num_b * p1b + num_c)
p1c = (vx + 4.0)
p5 = (num_a * p1c**2 + num_b * p1c + num_c)
p1n = (vx - 1.0)
p2n = (num_a * p1**2 + num_b * p1 + num_c)
p1an = (vx - 2.0)
p3n = (num_a * p1a**2 + num_b * p1a + num_c)
p1bn = (vx - 3.0)
p4n = (num_a * p1b**2 + num_b * p1b + num_c)
p1cn = (vx - 4.0)
p5n = (num_a * p1c**2 + num_b * p1c + num_c)
print ("Points of your Parabola: \n(%s, %s), (%s, %s) \n(%s, %s), (%s, %s) \n(%s, %s), (%s, %s) \n(%s, %s), (%s, %s)") % (p1, p2, p1n, p2n, p1a, p3, p1an, p3n, p1b, p4, p1bn, p4n, p1c, p5, p1cn, p5n)
print"=" * x
print ("Your x-intercepts are the two points where y = 0.0\n\nif it's not there, the point is not a whole number.\n\nHowever, these are all points on the parabola.")
print"=" * x
ts(1)
print ("Want another transformation? [y/n]")
x = [p1, p1n, p1a, p1an, p1b, p1bn, p1c, p1cn]
y = [p2, p2n, p3, p3n, p4, p4n, p5, p5n]
focus = (vx, yfocus)
vertex = (vx, vy)
plt.scatter(x,y, label="Scatter", color="c", marker='+', s=100,)
plt.scatter(vx, yfocus, label="Focus", color="k", marker='^', s=200)
plt.scatter(vx, vy, label="Vertex", color="m", marker='*', s=200)
plt.xlabel("X")
plt.ylabel("Y")
plt.title("Parabola")
plt.legend()
plt.show()
elif user_input=='no':
print ("Oops, try again.")
sys.exit()
user_input = raw_input(":")
if user_input=='y':
def restart_program():
"Restarts program"
os.execl(python, python, *sys.argv)
elif user_input=='n':
quit