Results 1 to 2 of 2

Thread: working with lines in circles or angles

  1. #1
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,524

    working with lines in circles or angles

    sometimes drawing lines in circles, or at specific angles can get a bit confusing
    here are some simple methods to do some of those, most have been posted in vb6 forum at some time, these methods should work in a picturebox or form, and probably printer

    to draw a line from a point at an angle to a specific length
    vb Code:
    1. Dim n As Long, l As Long, x1 As Long, x2 As Long, y1 As Long, y2 As Long
    2. Pic1.Cls
    3. n = 60 'degrees, working clockwise
    4. l = 1500 'length
    5. X1 = 1800 ' starting points
    6. Y1 = 1800
    7. X2 = X1 + l * Sin(n * 3.142 / 180)  'ending points
    8. Y2 = Y1 - l * Cos(n * 3.142 / 180)
    9. Pic1.Line (X1, Y1)-(X2, Y2), vbRed  ' draw the line

    to put a spiral in a picturebox
    vb Code:
    1. Const radians = 3.142 / 180   ' pi could be specifies more accurately if required
    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. Dim psx As Double, psy As Double
    5. Pic1.Cls   ' start fresh
    6. px = Pic1.Width / 2
    7. py = Pic1.Height / 2
    8. r = 0 ' diameter of circle to sample 0 to start at center
    9. cnt = 50  'no of point to in each circle
    10. spir = 5   ' no of rings in spiral
    11. spirw = (py - r) / spir / cnt
    12. ReDim col(cnt * spir)   ' total number of points
    13. For i = 0 To cnt * spir - 1
    14.         r1 = 360 / cnt * (i) * radians '3.142 / 180
    15.         If Not i = 0 Then Pic1.Line (psx, psy)-(px + r * Sin(r1), py - r * Cos(r1)), vbRed  ' draw line between points on spiral
    16. '        Pic1.PSet (px + r * Sin(r1), py - r * Cos(r1)), vbRed 'this will plot each point instaed of drawing a line
    17.         '****
    18.         psx = px + r * Sin(r1): psy = py - r * Cos(r1)  ' remember point for next loop
    19. '            col(i) = Pic1.Point(px + r * Sin(r1), py - r * Cos(r1))  ' this will return the colour of the point into an array
    20.           r = r + spirw sets the radius for the next point
    21.  
    22. Next
    23. End Sub

    i will also attach a simple project of a clock the demonstrates positioning lines in a circle and moving line controls with a timer, note the resizing does not work correctly if the window is maximised, i have tried to explain all the processes, except the actual math
    Attached Files Attached Files
    Last edited by westconn1; Jul 13th, 2008 at 04:57 PM.
    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

  2. #2
    Junior Member
    Join Date
    May 12
    Location
    I Live in Ulo Nnam, Nigeria. Nwa afo ka mbu.
    Posts
    26

    Re: working with lines in circles or angles

    THANKS for these foot prints, with them i am sure to cover miles.(GRAETFULL)

Posting Permissions

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