problem in fitting graph in accurate Cartesian

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • duaaayyad
    New Member
    • Apr 2013
    • 1

    problem in fitting graph in accurate Cartesian

    Hi
    thank you very much for your help
    I have some problems in drawing graphs in vb6
    first : how can I fit the graph to start from a certain point x+1 is the same as x it seems the same start even x+1 must shift up one step

    second can the drawn graph be in centimeter instead of pixel >>> so that the step can be shwon clearly

    third : how we can use coordinates fit on gapgh or we can just use a picture shws it

    his is my school small project in vb6 its for drawing graphs for functions in math

    give me feed back and help please



    Code:
    
    Const pi = 3.14159265358979
    
    Private Sub Combo1_Click()
    Picture1.ScaleTop = 500
     
    
    Picture1.ScaleLeft = -50
     
    
    Picture1.ScaleWidth = 100
     
    
    Picture1.ScaleHeight = -1000
     
    Picture1.DrawWidth = 2
    
    If Combo1.ListIndex = 0 Then
    
     b = InputBox("enter x factor")
     c = InputBox("enter the free value of x")
      Picture1.Line (-60, 10 * -c)-(60, 10 * -c)
     Picture1.Line (0, 500)-(0, -500)
    
     For X = -30 To 30 Step 0.01
      Y = b * X + c
     Picture1.PSet (X, Y), vbBlue
     Next X
    End If
    If Combo1.ListIndex = 1 Then
    Picture1.Cls
     a = InputBox("enter x2 factor")
    
     b = InputBox("enter x factor")
     c = InputBox("enter the free value of x")
    '   Picture1.Line (-40, 10 * -c)-(40, 10 * -c)
    ' Picture1.Line (0, 400)-(0, -400)
      Picture1.Line (-60, 10 * -c)-(60, 10 * -c)
     Picture1.Line (0, 500)-(0, -500)
    
     For X = -20 To 20 Step 0.01
      Y = a * X ^ 2 + b * X + c
     Picture1.PSet (X, Y), vbBlue
     Next X
    End If
    If Combo1.ListIndex = 2 Then
    
     a = InputBox("enter x3 factor")
     b = InputBox("enter x2 factor")
     c = InputBox("enter x factor")
     
     d = InputBox("enter the free value of x")
       
       Picture1.Line (-40, 10 * -d)-(40, 10 * -d)
     Picture1.Line (0, 400)-(0, -400)
    
     For X = -20 To 20 Step 0.01
      Y = a * X ^ 3 + b * X ^ 2 + c * X + d
     Picture1.PSet (X, Y), vbBlue
     Next X
    End If
    
    
    End Sub
    
    
    Private Sub Combo2_Click()
     Dim CenterX As Long, CenterY As Long
     Dim X As Double, Y As Double
     Dim Ax As Double, Ay As Double
     'Adjust these values to fit your need.
     If Combo2.ListIndex = 0 Then
     
    Picture1.Cls
    
     Ax = 10
     Ay = 50
     With Picture1
     .ScaleMode = vbPixels
     CenterX = .ScaleWidth / 2
     CenterY = .ScaleHeight / 2
     Picture1.Line (CenterX, .ScaleTop)-(CenterX, .ScaleHeight), vbBlack
     Picture1.Line (.ScaleLeft, CenterY)-(.ScaleWidth, CenterY), vbBlack
     b = InputBox("in (a+sin bx) enter cos factor b")
     c = InputBox("enter the other free factor a")
    
     For X = 0 To 2 * CenterX Step 0.2
     Y = -Ay * b * Sin(c * ((X - CenterX) / Ax)) + CenterY
     Picture1.PSet (X, Y), vbBlue
     Next
     End With
     End If
     
      If Combo2.ListIndex = 1 Then
    Picture1.Cls
    
     Ax = 10
     Ay = 50
     With Picture1
     .ScaleMode = vbPixels
     CenterX = .ScaleWidth / 2
     CenterY = .ScaleHeight / 2
     Picture1.Line (CenterX, .ScaleTop)-(CenterX, .ScaleHeight), vbBlack
     Picture1.Line (.ScaleLeft, CenterY)-(.ScaleWidth, CenterY), vbBlack
       b = InputBox("in (a+cos bx) enter cos factor b")
     c = InputBox("enter the other free factor a")
    
     For X = 0 To 2 * CenterX Step 0.2
     Y = -Ay * b * Cos(c * ((X - CenterX) / Ax)) + CenterY
     Picture1.PSet (X, Y), vbBlue
     Next
     End With
     End If
      If Combo2.ListIndex = 2 Then
    Picture1.Cls
    
     Ax = 10
     Ay = 50
     With Picture1
     .ScaleMode = vbPixels
     CenterX = .ScaleWidth / 2
     CenterY = .ScaleHeight / 2
     Picture1.Line (CenterX, .ScaleTop)-(CenterX, .ScaleHeight), vbBlack
     Picture1.Line (.ScaleLeft, CenterY)-(.ScaleWidth, CenterY), vbBlack
     For X = 0 To 2 * CenterX Step 0.2
     Y = -Ay * Tan((X - CenterX) / Ax) + CenterY
     Picture1.PSet (X, Y), vbBlue
     Next
     End With
     End If
    
      If Combo2.ListIndex = 3 Then
    Picture1.Cls
    
     Ax = 10
     Ay = 50
     With Picture1
     .ScaleMode = vbPixels
     CenterX = .ScaleWidth / 2
     CenterY = .ScaleHeight / 2
     Picture1.Line (CenterX, .ScaleTop)-(CenterX, .ScaleHeight), vbBlack
     Picture1.Line (.ScaleLeft, CenterY)-(.ScaleWidth, CenterY), vbBlack
     For X = 0 To 2 * CenterX Step 0.2
     Y = -Ay * Sin((X - CenterX) / Ax) ^ 2 + CenterY
     Picture1.PSet (X, Y), vbBlue
     Next
     End With
     End If
    
      If Combo2.ListIndex = 4 Then
    Picture1.Cls
    
     Ax = 10
     Ay = 50
     With Picture1
     .ScaleMode = vbPixels
     CenterX = .ScaleWidth / 2
     CenterY = .ScaleHeight / 2
     Picture1.Line (CenterX, .ScaleTop)-(CenterX, .ScaleHeight), vbBlack
     Picture1.Line (.ScaleLeft, CenterY)-(.ScaleWidth, CenterY), vbBlack
     For X = 0 To 2 * CenterX Step 0.2
     Y = -Ay * Cos((X - CenterX) / Ax) ^ 2 + CenterY
     Picture1.PSet (X, Y), vbBlue
     Next
     End With
     End If
    
     End Sub
    
    Private Sub Command1_Click()
    Picture1.Cls
    Picture1.ScaleTop = 500
     
    
    Picture1.ScaleLeft = -50
     
    
    Picture1.ScaleWidth = 100
     
    
    Picture1.ScaleHeight = -1000
     
    Picture1.DrawWidth = 2
     Picture1.Line (-40, 0)-(40, 0)
     Picture1.Line (0, 400)-(0, -400)
    
    
    
    End Sub
    
    Private Sub Form_Load()
    Picture1.ScaleTop = 500
     
    
    Picture1.ScaleLeft = -50
     
    
    Picture1.ScaleWidth = 100
     
    
    Picture1.ScaleHeight = -1000
     
    Picture1.DrawWidth = 2
     Picture1.Line (-40, 0)-(40, 0)
     Picture1.Line (0, 400)-(0, -400)
    
    
    Combo1.AddItem "linear "
    Combo1.AddItem " sqaure"
    Combo1.AddItem "Cubicaم"
    
    Combo2.AddItem "sin "
    Combo2.AddItem " cos"
    Combo2.AddItem "tan"
    Combo2.AddItem "sin2"
    
    Combo2.AddItem "cos2"
    
    
    End Sub
    
    
    Private Sub Label3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Label3.Caption = " ÚÒíÒí ÇáØÇáÈ " & Chr(10) & " Ýí ÇÞÊÑÇä ßËíÑ ÇáÍÏæÏ " & Chr(10) & "ÃÓ3 + È Ó2 + Ì Ó + Ï" & Chr(10) & " à åí ãÚÇãá Ó3 æ È åí ãÚÇãá Ó2 æ Ì åí ãÚÇãá Ó æ Ï åí ÇáÍÏ ÇáãØáÞ"
    End Sub
    
    
    Private Sub Label4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Label4.Caption = " ÚÒíÒí ÇáØÇáÈ " & Chr(10) & " Ýí ÇÞÊÑÇäÇÊ ÇáãËáËíÉ " & Chr(10) & "à ÌÇÈ Ó Ãæ ÃÌÊÇ È Ó" & Chr(10) & " à åí ãÚÇãá ÇáÌíÈ Çæ ÇáÌÊÇ æ È åí ãÚÇãá ÇáÒÇæíÉ"
    
    End Sub
Working...