Hallo vb_checker,
In Visual Basic kann man eine Parabel zeichnen wie folgend:
Es gibt ein Form (Form1) , ein PictureBox (Picture1) und drei Knöpfe (Command1, Command2 und Command3)
Command1 ist für das zeichnen des Koordinatensystem.
Command2 ist für das zeichnen der Parabel.
Command3 ist das Clear für die PictureBox
Auf Knopf Command1 kommt der Code:
Dim i As Integer
Dim Breite As Integer
Dim Hoehe As Integer
Dim abstand As Single
Breite = Picture1.ScaleWidth
Hoehe = Picture1.ScaleHeight
Picture1.ForeColor = QBColor(0)
ScaleMode = 6 '// Die Maßeinheit ist mm
Picture1.Line (0 + 3, Hoehe / 2)-(Breite - 3, Hoehe / 2) '//x-Achse
Picture1.Line (Breite / 2, 0 + 3)-(Breite / 2, Hoehe - 3) '//y-Achse
'//Skala x-Achse
abstand = (Breite - 6) / 10
For i = 0 To 10
Picture1.Line (i * abstand + 3, Hoehe / 2 - 1)-(i * abstand + 3, Hoehe / 2 + 1)
Next i
'//Skala y-Achse
abstand = (Hoehe - 6) / 10
For i = 0 To 10
Picture1.Line (Breite / 2 - 1, i * abstand + 3)-(Breite / 2 + 1, i * abstand + 3)
Next i
Picture1.ForeColor = QBColor(1)
Picture1.FontBold = True
'//x-Achse Punkte
For i = 0 To 10 Step 1
abstand = (Breite - 6) / 10
Picture1.CurrentX = abstand * i + 1
Picture1.CurrentY = Hoehe / 2 + 2
Picture1.Print i - 5
Next i
'//y-Achse Punkte
For i = 10 To 0 Step -1
abstand = (Hoehe - 6) / 10
Picture1.CurrentX = Breite / 2 + 1
Picture1.CurrentY = abstand * i + 1
Picture1.Print (i - 5) * (-1)
Next i
Auf Knopf Command2 kommt der Code (der die Parabel zeichnet):
Dim i As Single
Dim Breite As Integer '// Breite der PictureBox
Dim Hoehe As Integer '// Hoehe der PictureBox
Dim schritt_x As Single '//Skalierung x
Dim schritt_y As Single '//Skalierung y
Dim y As Single
Dim x As Single
Dim xpos As Single
Dim ypos As Single
ScaleMode = 6 '// Die Maßeinheit ist mm
Breite = Picture1.ScaleWidth
Hoehe = Picture1.ScaleHeight
Picture1.ForeColor = QBColor(1) '//Zeichenfarbe
Picture1.DrawWidth = 1 '//Liniendicke festlegen
schritt_x = (Breite - 6) / 10
schritt_y = (Hoehe - 6) / 10
For i = -5 To 5 Step 0.0005
x = i
xpos = (Breite / 2 + x * schritt_x)
y = ((x - 3) ^ 2) - 2 '//Das ist die Funktion der Parabel --> hier (x-3)^2-2 Hier kann man ändern mit andere Parabeln.
ypos = Hoehe / 2 + y * schritt_y * (-1)
Picture1.PSet (xpos, ypos)
Next i
Auf Knopf Command3 kommt der Code:
Picture1.Cls '//Picture löeschen
Man kann mehrere Parabeln zeichnen eine über der andere.
Gruesse,