Results 1 to 5 of 5

Thread: drawing a coordinate plane...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    southwest pennsylvania
    Posts
    65

    drawing a coordinate plane...

    i'm making a program that adds vectores for my physics teacher, and i decided to make a picture box to draw the vectors... fun!

    anyway, the method of composition works fine, but the method of sines and cosines wont.

    how can i make it so the picbox automatically "zooms"? so if the user puts a vector with a magnitude of 15 or something it wont be tiny?

    i also want to make arrows show on the vectors, but im frying my brain trying to figure it out, maybe that sould be in the math forum.

    the listbox at the right is for showing work. im not that far yet...
    Attached Files Attached Files
    if you choose not to decide you still have made a choice!

    RUSH rocks!

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    southwest pennsylvania
    Posts
    65

    update

    i changed a few things around and added a table and written work.
    Attached Files Attached Files
    if you choose not to decide you still have made a choice!

    RUSH rocks!

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Hey, took me quite a while
    I had to change your picturebox so that it would be a square (has to have the same width and height, otherwise it's a little hard to change the scale).
    Anyways, I added two functions, createGraphicsEx and setScale. I replaced all of your picturebox.creategraphics with my own function. The way you had it, your graph would disappear after a paint event. (it wont now )
    setScale is supposed to zoom correctly, but there is something that you have to do yourself before it works:
    VB Code:
    1. Private minMag As Integer = Integer.MaxValue    ' Leave the initial values like this
    2. Private m***** As Integer = Integer.MinValue
    3.  
    4. Private Sub setScale(ByVal gr As Graphics)
    5.         ' You need a code that would determine the correct value of minMag and m*****
    6.         minMag = -5
    7.         m***** = picResult.Width / 2
    8.  
    9.         Dim newSize As Integer = m***** - minMag
    10.         Dim drawScale As Single = picResult.ClientSize.Width / newSize
    11.         ' Zoom in
    12.         gr.ScaleTransform(drawScale, drawScale)
    13.  
    14.         Dim screenTop As Integer = picResult.ClientSize.Height \ 2 - m*****
    15.         Dim screenLeft As Integer = picResult.ClientSize.Width \ 2 + minMag
    16.  
    17.         ' Locate the vectors
    18.         gr.TranslateTransform(-screenLeft, -screenTop)
    19.     End Sub

    minMag and m***** are supposed to be the minimum and maximum.... what you have to do is to get the x and y component of ALL the vectors. then you have to do something like this:
    VB Code:
    1. for each vector...
    2. ' get the start and end point coordinate of each vector
    3. ' for example (x1,y1) is the start point and (x2,y2) is the end point of the vector
    4. '..... missing code
    5.  
    6. if x1< minmag then minmag = x1
    7. if y1< minmag then minmag = y1
    8.  
    9. if x2>m***** then m***** = x2
    10. if y2>m***** then m***** = y2
    11.  
    12. next
    btw I'm assuming that you may have some vectors that wont start from 0,0
    right now, the way your program is, (x1, y1) would always be (0,0)


    minMag is supposed to be the smallest component in the vectors (x or y component of the vector), and m***** is supposed to be the largest component in all the vector (x or y component)



    I hope it makes sense. Right now if you run the program and add any vector, it will zoom from (-5,-5) to (width/2,width/2)
    btw if you comment the setScale sub,it will do exactly what your program was doing before
    Attached Files Attached Files
    Last edited by MrPolite; Jan 20th, 2003 at 03:56 PM.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    southwest pennsylvania
    Posts
    65
    thank you very much!
    right now it doesnt all make sense, but i'll sort through it.
    THANK YOU!
    if you choose not to decide you still have made a choice!

    RUSH rocks!

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    it's totally not professional though
    it's zooming the whole thing, which means that your graphed lines will be thicker too, which isnt' quite good..
    edit: aah I'm sure there are better ways.... take a look at the drawing2d.matrix class also
    Last edited by MrPolite; Jan 20th, 2003 at 07:21 PM.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width