dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: plotting a quadratic graph

  1. #1
    Join Date
    Dec 2006
    Posts
    1

    plotting a quadratic graph

    Hello everyone.
    can someone please help? i am trying to write a program to plot quadratic and line graph given 2 arrays(x,y).
    i tried the folowing but its not working.

    W = P.Width
    H = P.Height
    WM = W / 2
    HM = H / 2
    P.Line (0, HM)-(W, HM), vbRed
    P.Line (WM, 0)-(WM, H), vbRed

    MAXY = v(0)
    For I = 1 To N
    If MAXY < v(I) Then
    MAXY = v(I)
    End If
    Next I

    MAXX = 5
    OX = 0
    OY = 0
    ScaleX1 = W / N
    ScaleY1 = H / N
    For I = 0 To N
    If v(I) > 0 Then
    YT = WM + ((WM * v(I)) / MAXY)
    Else
    YT = WM - ((WM * -v(I)) / MAXY)
    End If
    If t(I) > 0 Then
    TT = HM + ((HM * t(I)) / MAXX)
    Else
    TT = HM - ((HM * -t(I)) / MAXX)
    End If
    OX = OX + ScaleX1
    OY = OY + ScaleY1
    P.Line -(TT, YT)

    Next I
    can someone please help?

  2. #2
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    If it's "quadratic" then "N" must = 3 is it true ?

    I just need to know your algorithm to have this shape from array ,
    I think line similar to this are not clear :
    " YT = WM + ((WM * v(I)) / MAXY) "
    After my caluclations this equation generate a "quadratic" form but the problem is to have good matrix .

    If u mean that those arrays holds x,y positions so try this will make good work :

    Code:
    WM = p.Width / 2
    HM = p.Height / 2
    p.Line (0, HM)-(W, HM), vbRed
    p.Line (WM, 0)-(WM, H), vbRed
    
    For i = 0 To 3
    p.Line -(v(i), t(i))
    Next
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  3. #3
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    I can help you by taking your code and creating a simple test project that plots your graph in a picture box; but I need sample data for the V and T arrays. You should select data that you would recognize what the graph should look like. This way if my results look wrong we can figure out what is throwing it off.

  4. #4
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    Ok I started a simple test project to play around with. It plots the graph and scales it to fit within the picture box. I played around with your code a bit also. Since in VB the X axis is horizontal and the Y axis is veritcal I changed some variable names to refelect this better. Also notice that I set the ScaleMode to pixels so the lines would plot easier. I left your original code in a different sub for reference.
    Last edited by Ron Weller; 05-30-2008 at 10:18 PM.

  5. #5
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    well, you are doing too much scaling.
    VB is great to plot this kind of data, because you can set the scale (both horizontal and vertical) of the printing/displaying object as you wish, using the scale property.
    Just use:

    myPictureBox.scale = (MinX, MaxY)-(MaxX, MinY)

    where the parameters are the range of your coordinate, minimum and maximum, and you do not have to scale anything, just use your coordinate, for example this draw a rectangle in the middle of the form (code to be used in the Paint event unless the AutoRedraw property was set):

    Me.Scale (0, 100)-(100, 0)
    Me.Line (25, 25)-Step(50, 50), , B

    Incidentally, if you put the drawing code in a sub and you pass to it the Graphic object (like a PictureBox or a Printer) you can implement a Printing app with Preview.

    Let us know how it goes
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

Similar Threads

  1. Replies: 6
    Last Post: 09-22-2006, 12:52 PM
  2. Replies: 1
    Last Post: 06-23-2006, 12:42 AM
  3. Help on making a Graph for applet
    By crawf in forum Java
    Replies: 4
    Last Post: 06-04-2006, 05:10 PM
  4. Access/MS Graph Question...
    By merlicky in forum Database
    Replies: 4
    Last Post: 05-12-2006, 09:56 AM
  5. Adjacency list representation of a graph
    By ThePrise in forum Java
    Replies: 4
    Last Post: 11-23-2005, 02:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center