Interactive tool to visualize quadratic equations and compare VB6 and VB.NET implementations
A quadratic function is a second-degree polynomial function of the form: f(x) = ax2 + bx + c, where a, b, and c are constants, and a ≠ 0. The graph of a quadratic function is a parabola, which can open upwards or downwards depending on the sign of the coefficient 'a'.
This interactive tool allows you to visualize quadratic equations by adjusting the coefficients a, b, and c. You can see the parabola shape, vertex point, axis of symmetry, and roots (if they exist). The tool also provides equivalent code implementations in both VB6 and VB.NET.
Vertex: (0.00, 0.00)
Axis of Symmetry: x = 0.00
Roots: No real roots
Below are the implementations for plotting quadratic functions in both VB6 and VB.NET. The VB.NET version uses modern GDI+ capabilities for smoother rendering.
Private Sub cmd_draw_Click() Dim a As Single, b As Single, c As Single Dim w As Single, v As Single ' Get coefficients from user input a = Val(txt_a.Text) b = Val(txt_b.Text) c = Val(txt_c.Text) ' Clear previous graph pic_graph.Cls ' Draw coordinate axes pic_graph.Line (0, pic_graph.ScaleHeight / 2)-(pic_graph.ScaleWidth, pic_graph.ScaleHeight / 2), vbBlack pic_graph.Line (pic_graph.ScaleWidth / 2, 0)-(pic_graph.ScaleWidth / 2, pic_graph.ScaleHeight), vbBlack ' Calculate and plot the graph For w = 0 To pic_graph.ScaleWidth Step 0.1 ' Transform coordinates to center of picture box Dim x As Single Dim y As Single x = (w - pic_graph.ScaleWidth / 2) / 20 ' Scale factor y = a * x ^ 2 + b * x + c v = pic_graph.ScaleHeight / 2 - y * 20 ' Scale and transform ' Plot point if within bounds If v >= 0 And v <= pic_graph.ScaleHeight Then pic_graph.PSet (w, v), vbBlue End If Next w ' Display vertex information Dim vertexX As Single, vertexY As Single vertexX = -b / (2 * a) vertexY = a * vertexX ^ 2 + b * vertexX + c lblVertex.Caption = "Vertex: (" & Format(vertexX, "0.00") & ", " & Format(vertexY, "0.00") & ")" End Sub Private Sub Command1_Click() ' Clear the graph and input fields pic_graph.Cls txt_a.Text = "" txt_b.Text = "" txt_c.Text = "" lblVertex.Caption = "" End Sub
VB6 uses the PSet method for plotting points, which is less efficient than modern approaches but sufficient for simple graphs.
Private Sub PlotGraph(sender As Object, e As EventArgs) Handles btnPlot.Click Dim a As Double = Double.Parse(txtA.Text) Dim b As Double = Double.Parse(txtB.Text) Dim c As Double = Double.Parse(txtC.Text) ' Create a new bitmap for drawing Dim graphBitmap As New Bitmap(picGraph.Width, picGraph.Height) Using g As Graphics = Graphics.FromImage(graphBitmap) g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias g.Clear(Color.White) ' Draw coordinate axes Dim centerX As Integer = picGraph.Width \ 2 Dim centerY As Integer = picGraph.Height \ 2 g.DrawLine(Pens.Black, 0, centerY, picGraph.Width, centerY) g.DrawLine(Pens.Black, centerX, 0, centerX, picGraph.Height) ' Calculate and draw the quadratic function Dim scale As Double = 20.0 ' Pixels per unit Dim path As New Drawing2D.GraphicsPath() Dim firstPoint As Boolean = True For x As Double = -10 To 10 Step 0.1 Dim y As Double = a * x * x + b * x + c Dim pixelX As Integer = centerX + (x * scale) Dim pixelY As Integer = centerY - (y * scale) If firstPoint Then path.StartFigure() path.AddLine(pixelX, pixelY, pixelX, pixelY) firstPoint = False Else path.AddLine(path.GetLastPoint(), New PointF(pixelX, pixelY)) End If Next g.DrawPath(Pens.Blue, path) ' Calculate and mark vertex Dim vertexX As Double = -b / (2 * a) Dim vertexY As Double = a * vertexX * vertexX + b * vertexX + c Dim vertexPixelX As Integer = centerX + (vertexX * scale) Dim vertexPixelY As Integer = centerY - (vertexY * scale) g.FillEllipse(Brushes.Red, vertexPixelX - 4, vertexPixelY - 4, 8, 8) g.DrawString($"Vertex ({vertexX:F2}, {vertexY:F2})", New Font("Arial", 10), Brushes.Red, vertexPixelX + 5, vertexPixelY - 10) End Using ' Display the graph picGraph.Image = graphBitmap ' Display equation information lblEquation.Text = $"f(x) = {a}x² + {b}x + {c}" lblVertex.Text = $"Vertex: ({vertexX:F2}, {vertexY:F2})" End Sub
VB.NET uses GDI+ for smoother graphics, anti-aliasing, and better performance, making it the preferred choice for modern applications.
If a > 0, the parabola opens upwards. If a < 0, it opens downwards.
The vertex point is at x = -b/(2a), y = f(-b/(2a)). This is the maximum or minimum point.
The vertical line x = -b/(2a) that divides the parabola into two symmetric halves.
Solutions to ax² + bx + c = 0, calculated as [-b ± √(b² - 4ac)]/(2a).