2017年12月12日 星期二

VB2010-繪製A*X^2+B*X+C=0一元二次方程式

[VB2010]-繪製A*X^2+B*X+C=0一元二次方程式

以圖形表示A*X^2+B*X+C=0一元二次方程式,其中A,B,C三個係數可由;

執行者從TextBox輸入。




Public Class Form1
    Dim Painting As Bitmap
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Painting = New Bitmap(400, 400)
        Dim g As Graphics = Graphics.FromImage(Painting)
        Dim A, B, C, XA, XB As Integer
        Dim X, Y, oldX1, oldY1, ShfX, ShfY, X2, Y2, Fc As Single
        Dim P As Pen = New Pen(Color.Black, 1)
        Dim P1 As Pen = New Pen(Color.Violet, 1)
        Dim P2 As Pen = New Pen(Color.Blue, 1)
        Const Cv As Single = 0.0174523
        Dim lX, lY As Single
        A = Val(TextBox1.Text)
        B = Val(TextBox2.Text)
        C = Val(TextBox3.Text)

        lX = -1000
        lY = -1000
        ShfX = 100
        ShfY = 120
        Fc = 0.005
        A = Val(TextBox1.Text)
        B = Val(TextBox2.Text)
        C = Val(TextBox3.Text)


        g.DrawLine(P1, 0, ShfY, ShfX * 2 * 2, ShfY)
        g.DrawLine(P1, ShfX * 2, 0, ShfX * 2, ShfY * 2)

        For Y = -20000 To 20000 Step 2000
            g.DrawLine(P2, ShfX * 2 - 10, ShfY - Y * Fc, ShfX * 2 + 10, ShfY - Y * Fc)
        Next

        For X = -250 To 250 Step 0.1
            Y = A * X ^ 2 + B * X + C
            P = New Pen(P.Color, 1)

            g.DrawLine(P, (lX + ShfX) * 2, -lY + ShfY, (X + ShfX) * 2, -Y + ShfY)


            lX = X
            lY = Y
        Next X

        Me.BackgroundImageLayout = ImageLayout.None
        Me.BackgroundImage = Painting
    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub
End Class

沒有留言:

張貼留言

WOKWI LED + MQTT Node-Red SQLite

WOKWI LED + MQTT Node-Red SQLite const char *mqtt_broker = "broker.mqtt-dashboard.com" ; const char *topic1 = "alex9ufo/e...