Results 1 to 7 of 7

Thread: Can I draw smooth curve in VB?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    48

    Can I draw smooth curve in VB?

    Can I draw smooth x VS y curve in VB like smooth line curve in Pivot Chart in access? Or, can i use Pivot chart in VB?

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Can I draw smooth curve in VB?

    What about using the intrinsic 'Circle()' function ? (you can specify an arc length)

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    48

    Re: Can I draw smooth curve in VB?

    can I draw any curve (2d xy curve) using circle? I have two coulmn X and Y in my table which have random values. I want to draw a smooth X Versus Y line curve.

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Can I draw smooth curve in VB?


  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Can I draw smooth curve in VB?

    Ahh, ok ignore (both) those posts

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Can I draw smooth curve in VB?

    How about PSet() ?

    You could iterate the x and y values and place a pixel on the screen (or other container).

    Thinking that tru, you may end up without lines between the points - probably unwanted.

    These may help: http://vbforums.com/search.php?searchid=1442707

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Can I draw smooth curve in VB?

    if you place the dots close enough together it is a line

    here is an example that plots a spiral. originally it was just dots (50 points per circle), but i change it to 5000 and it is a solid line (as far as you and i can see)

    vb Code:
    1. Sub extrasub()
    2. Dim col() As Long, r1 As Double, r As Double, px As Double
    3. Dim py As Double, cnt As Long, spir As Long, spirw As Double
    4. Pic1.Cls
    5. px = Pic1.Width / 2
    6. py = Pic1.Height / 2
    7. r = 0 ' diameter of circle to sample 0 to start at center
    8. cnt = 5000  'no of point to sample in circle
    9. spir = 5   ' no of rings in spiral
    10. spirw = (py - r) / spir / cnt
    11. 'Text1(0).Move px, py
    12. ReDim col(cnt * spir)
    13. For i = 0 To cnt * spir - 1
    14.         r1 = 360 / cnt * (i) * radians '3.142 / 180
    15.         Pic1.PSet (px + r * Sin(r1), py - r * Cos(r1)), vbRed 'i used this to put a circle i could see for testing
    16.             col(i) = Pic1.Point(px + r * Sin(r1), py - r * Cos(r1))
    17.           r = r + spirw '(py - 1000) / spir / cnt
    18.  
    19. Next
    20.  
    21. End Sub

    so you just need to plot enough points on your curve,
    or else join the dots together change the code like this
    vb Code:
    1. If Not i = 0 Then Pic1.Line (psx, psy)-(px + r * Sin(r1), py - r * Cos(r1)), vbRed
    2. '        Pic1.PSet (px + r * Sin(r1), py - r * Cos(r1)), vbRed 'i used this to put a circle i could see for testing
    3.         '****
    4.         psx = px + r * Sin(r1): psy = py - r * Cos(r1)
    declare psx and psy both as double

    with 50 points on each circle
    Last edited by westconn1; Aug 27th, 2007 at 03:44 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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