seinem eigenen code gegenüber ist man einfach zu wenig kritisch...
Soooo...
hab mich noch mal rangesetzt und versuche jetzt mir die parabel noch zeichnen zu lassen. Leider funktioniert es aber noch nicht so ganz.
es wird kein fehler ausgegebn aber man kann nur so vage erkennen, da das mal ne parabel werden soll. kopiert euch den code ins idle und startet das programm gebt am besten die werte 1,2,3,4,1 ein und guckt was er ausgibt.
Code: Alles auswählen
# -*- coding: utf-8 -*-
from Tkinter import *
class Koordinatensystem:
def __init__(self, canvas):
kreuz=canvas.create_line(0,250,499,250, fill='black')+canvas.create_line(250,0,250, 499, fill='black')
pfeily=canvas.create_line(250,0,240,10)+canvas.create_line(250,0,260,10)
pfeilx=canvas.create_line(499,250,489,240, fill='black')+canvas.create_line(499,250,489,260, fill='black')
x=canvas.create_text(480, 260, text='X')
y=canvas.create_text(240, 20, text='Y')
class Parabel:
def __init__(self, master, canvas):
def formelholen(xa, ya, xb, yb, a2):
global a1p
global a0p
a1p=(a2*xa**2-a2*xb**2-ya+yb)/(xb-xa)
a0p=ya-a2*(xa**2)-a1p*xa
if master.xa.get()=='':
xa='0'
else:
xa=float(master.xa.get())
if master.ya.get()=='':
ya='0'
else:
ya=float(master.ya.get())
if master.xb.get()=='':
xb='0'
else:
xb=float(master.xb.get())
if master.yb.get()=='':
yb='0'
else:
yb=float(master.yb.get())
if master.a2.get()=='':
a2='0'
else:
a2=float(master.a2.get())
if master.xa.get()==master.ya.get()==master.xb.get()==master.yb.get():
parabel=canvas.create_text(100, 90, text='Angaben nicht eindeutig!\nNur ein Punkt!')
else:
formelholen(xa, ya, xb, yb, a2)
for x in range(-25, 25):
x1=x*10+250
x2=x*10+260
parabel=canvas.create_line(x1, 10*(a2*x**2+a1p*x+a0p)+250, x2, 10*(a2*(x+1)**2+a1p*(x+1)+a1p)+250) #irdendwas mit der funktion stimmt nicht so recht würde ich sagen
class Rechner:
def __init__(self, master):
def poly(xa, ya, xb, yb, a2):
a1=(a2*xa**2-a2*xb**2-ya+yb)/(xb-xa)
a0=ya-a2*(xa**2)-a1*xa
global TPO
TPO='f(x)='+ str(a2)+ 'x^2+'+ str(a1)+ 'x+'+ str(a0)+ '\n'
def scheitel(xa, ya, xb, yb, a2):
xs=(a2*xa**2-a2*xb**2-ya+yb)/(a2*2*(xa-xb))
ys=-a2*xa**2+2*a2*xa*xs-a2*xs**2+ya
global TS
TS='S('+ str(xs)+ '/'+ str(ys)+ ')\n'
def prod(xa, ya, xb, yb, a2):
p=(a2*xa**2-a2*xb**2-ya+yb)/(xb-xa)/a2
q=(ya-a2*xa**2-p*a2*xa)/a2
global TPR
if p**2/4-q>0:
n1=-p/2+(p**2/4-q)**(1/2)
n2=-p/2-(p**2/4-q)**(1/2)
TPR='Die Nullstellen lauten: '+ str(n1) +' und '+str(n2)
else:
TPR='Keine Nullstellen!'
def berechnen():
if self.xa.get()=='':
xa='0'
else:
xa=float(self.xa.get())
if self.ya.get()=='':
ya='0'
else:
ya=float(self.ya.get())
if self.xb.get()=='':
xb='0'
else:
xb=float(self.xb.get())
if self.yb.get()=='':
yb='0'
else:
yb=float(self.yb.get())
if self.a2.get()=='':
a2='0'
else:
a2=float(self.a2.get())
if xa==ya==xb==yb:
T='Angaben nicht eindeutig!\nNur ein Punkt!'
else:
poly(xa, ya, xb, yb, a2)
scheitel(xa, ya, xb, yb, a2)
prod(xa, ya, xb, yb, a2)
T=TPO+ TS+ TPR
fen=Toplevel(master)
mes=Label(fen, borderwidth=2, relief=RIDGE, text=T, font='arial 20 bold', fg='red', bg='yellow')
mes.grid(row=6)
def zeichnen():
koordsys=Koordinatensystem(self.tisch)
parabel=Parabel(self, self.tisch)
frame=Frame(master)
frame.grid()
self.xa=Entry(frame, justify=RIGHT)
self.xa.grid(row=0, column=0)
self.lxa=Label(frame, text='XA')
self.lxa.grid(row=0, column=1)
self.ya=Entry(frame, justify=RIGHT)
self.ya.grid(row=1, column=0)
self.lya=Label(frame, text='YA')
self.lya.grid(row=1, column=1)
self.xb=Entry(frame, justify=RIGHT)
self.xb.grid(row=2, column=0)
self.lxb=Label(frame, text='XB')
self.lxb.grid(row=2, column=1)
self.yb=Entry(frame, justify=RIGHT)
self.yb.grid(row=3, column=0)
self.lyb=Label(frame, text='YB')
self.lyb.grid(row=3, column=1)
self.a2=Entry(frame, justify=RIGHT)
self.a2.grid(row=4, column=0)
self.la2=Label(frame, text='A2')
self.la2.grid(row=4, column=1)
self.tisch=Canvas(frame, width=500, height=500, bg='white', borderwidth=1, relief=SOLID)
self.tisch.grid(row=5, column=0, columnspan=3)
self.schalterb=Button(frame, text='Berechnen', command=berechnen)
self.schalterb.grid(row=1, column=2)
self.schalterz=Button(frame, text='Zeichnen', command=zeichnen)
self.schalterz.grid(row=3, column=2)
root=Tk()
root.title('Parabelrechner')
app=Rechner(root)
root.mainloop()