Results 1 to 8 of 8

Thread: Ploting Points,Math And Recurse

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    4

    Angry Ploting Points,Math And Recurse

    [email protected]

    Ok Here We Go.
    I Realy Need Help With This Please.
    I Need Code To Cycle Through All 360 Degrees From A Point X,y

    The First Time Through
    0,45,90,180 Degrees Needs To Be 128 Pixels From Center

    The Second Time Through
    Should Be half way Between and + or - a Random number
    0 and 45,45 and 90,90 and 180, 180 and 360
    and the Length should Be Random

    The Third Time Through
    Should Be A Random Point Between 0 and The first Random Point Between 0 and 45, continueing on through the rest of the spaces

    need to be able to go from the first three cycles to say 36 cycles
    each time doing the random placement thing

    all points need to be in a PTS array Of X and Y Values
    so They Can Be Connected Like in The Picture
    Please View The Picture It May Make All This easier To Understand

    I Will Send $50.00 to
    The First Person To Send Me The Working Code With Comments So That I Can Understand How This Was Done.
    I Know $50.00 Isnt Much But Its All I Can Afford I HaveKids and A Mortage.
    Please Help Thanks
    Vincent Foster
    Attached Images Attached Images  

  2. #2
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    huh?

    Do you know any trig at all?

    2 * PI Radians = 360 Degrees

    0, 45, 90, 135, 180 = (for i = 0 to 4) : (i * PI) / 4

    There's not alot of work here... if you really sit down and take out a piece of paper and a pen (maybe graphing paper) you should be able to get it in no time.

    Now the drawing part is the easiest... use the Line Method or the Circle one!

    The formula for a line is:

    y = m * x + b

    where m is the slope and b is the offset.

    also the formula for the degree stuff is:

    Code:
    
               /|
      Hypo-   /_|
       tnuse / a|
            /   | Adjacent
           /    |
          /     |
          -------
             Opposite
    
     Sin(a) = Opp / Hyp
     Cos(a) = Adj / Hyp
     Tan(a) = Opp / Adj
    I dont want your money-- I would love to do this (for free) but unfortunately im a bit busy at the mom... this is the kind of stuff that you need to use what u learned back in jr. high... its a "thinking" problem. Also, if you have any specific questions, just post them. Maybe someone will do it for you or even show you have or whatever.

    Good Luck,
    MoMad
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  3. #3
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625

    btw

    by the way, this is NOT a recursive problem... at least judging the way you explained it.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  4. #4
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    Are you trying to draw a 'radar' graph?

    If yes then this will get you started:
    VB Code:
    1. Public Type Point
    2.     X As Long
    3.     Y As Long
    4. End Type
    5. Private Const pi = 3.14159265358979
    6. Public Sub DrawRadarGraph(Center As Point, Radius As Long, ByRef Values() As Long, MaxValue As Long)
    7.     Dim Points() As Point
    8.     ReDim Points(UBound(Values()))
    9.     Form1.Circle (Center.X, Center.Y), Radius
    10.     ArrayMax = UBound(Values())
    11.     Angle = (360 / ArrayMax) * pi / 180
    12.     For i = 0 To ArrayMax - 1
    13.         dx = Sin(i * Angle) * Radius
    14.         dy = Cos(i * Angle) * Radius
    15.         Form1.Line (Center.X, Center.Y)-Step(dx, dy)
    16.     Next i
    17.     For i = 0 To ArrayMax - 1
    18.         dx = Sin(i * Angle) * Values(i) / MaxValue * Radius
    19.         dy = Cos(i * Angle) * Values(i) / MaxValue * Radius
    20.         Points(i).X = Center.X + dx
    21.         Points(i).Y = Center.Y + dy
    22.     Next i
    23.     For i = 0 To ArrayMax - 2
    24.         Form1.Line (Points(i).X, Points(i).Y)-(Points(i + 1).X, Points(i + 1).Y)
    25.     Next i
    26.     Form1.Line (Points(ArrayMax - 1).X, Points(ArrayMax - 1).Y)-(Points(0).X, Points(0).Y)
    27. End Sub
    Last edited by TiPeRa; Jan 12th, 2002 at 08:59 AM.
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    4

    Link To Understand What Im Trying To Do

    http://www.gameprogrammer.com/fractal.html

    I Need To Put The 2d Part In A Circle and The Line Format.

  6. #6
    Zaei
    Guest
    TO plot a point on a circle, use this function:
    Code:
    px = r * cos(theta) + cx
    py = r * sin(theta) + cy
    To convert from degrees to radians (since the trig functions require radians), multiply the degree value by (pi / 180).

    To do what you want, simply change the value of r, as it is the distance from the center of the circle. cx and cy is the center of the circle. theta is the radian value. For instance, if you wanted a point plotted at 100 twips from the center, at 45 degrees, with the center at (200, 450), it would look like this:
    Code:
    px = 100 * cos(45 * (3.14159 / 180)) + 200
    py = 100 * sin(45 *(3.14159 / 180)) + 450
    Z.

  7. #7
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi Vincent
    First of all, i dont want your money Buy the kids something nice with it.

    The problem is not so difficult in visualising but most of the complexity comes from your requirement to 'remember' each line drawn to get lines for new passes and also in ordering these lines so that you can join the spokes up. I had it all finished last night my time but was too bleary to work out the ordering for the joining of the spokes. NB The code is MUCH smaller without these connections!

    Anyway, here is your code. You need only to have a command button and a picture box on form1. You can keep clicking the command button to get new graphs.

    Regards
    Stuart
    VB Code:
    1. 'Type holding details about every spoke
    2. Private Type MyPointType
    3.     Length As Long 'Length of spoke
    4.     CCWAngle As Long 'Counter clockwise angle limit
    5.                     'ie the next angle must be between this upper limit
    6.                     'and the lower limit set by the clockwise angle
    7.     Angle As Long 'The actual angle drawn
    8.     CWAngle As Long 'Clockwise angle limit
    9.     CurX As Single 'Actual X position
    10.     CurY As Single 'Actual Y Position
    11.     Order As Long 'Position in order for joining lines
    12. End Type
    13. Dim Points() As MyPointType
    14.  
    15. 'Type for details about the order of each spoke so that can connect lines
    16. Private Type MyOrderType
    17.     CurX As Single 'Actual X position
    18.     CurY As Single 'Actual Y Position
    19. End Type
    20. Dim PointsOrd() As MyOrderType
    21. Dim OrderStart() As Long 'Starting position in order of first line in each pass
    22. Dim OrderJump() As Long 'How much to jump to get next in order for that pass
    23.  
    24. Private Const pi As Single = 3.14159265 'Constant for Pi
    25. Private Const MaxRadius As Single = 128 'maximum length of spoke in pixels
    26. Private Const LineRand As Long = 41 'Random length shortening of spokes in pixels
    27. Private Const AngleRand As Single = 10 'Random percentage variance for each new angle
    28. Private Const NumPasses As Long = 2 'Number of passes
    29.  
    30. Dim Loop1 As Long 'Generic loops
    31. Dim Loop2 As Long
    32.  
    33. Private Sub Form_Load()
    34.     Randomize 'Start randomization
    35.     ReDim Points(1 To 2 ^ (NumPasses + 2)) 'Create array eg 2 passes = 16 lines
    36.     ReDim PointsOrd(1 To 2 ^ (NumPasses + 2)) 'Create array for lines in order
    37.     For Loop1 = 1 To 4 'Create starting axis
    38.         With Points(Loop1)
    39.             .Length = MaxRadius 'Full length lines
    40.             .CCWAngle = 90 * (Loop1 - 1) 'CCW limit of quadrant ie 0,90,180,270
    41.             .CWAngle = 90 * Loop1 'CW limit ie 90,180,270,360
    42.             .Angle = 90 * Loop1 'Actual angle ie 90,180,270,360
    43.             .Order = (2 ^ (NumPasses + 2)) / 4 * Loop1 'Where they appear in order of all spokes
    44.             'ie if there are 16 lines then the axis would be line 4,8,12 and 16
    45.         End With
    46.     Next
    47.  
    48.     Me.Show 'Show form
    49.     With Picture1
    50.         .AutoRedraw = True 'Set to redraw if covered
    51.         .Width = Screen.TwipsPerPixelX * 300 'Set width based on screen res
    52.         .Height = Screen.TwipsPerPixelY * 300
    53.         Picture1.Scale (-150, -150)-(150, 150) 'scale pic to 300 x 300
    54.     End With
    55.  
    56. End Sub
    57.  
    58. Private Sub Command1_Click()
    59.     Dim CurrentPosn As Long 'Current line being worked on
    60.     Dim PreviousPosn As Long 'Previous line gives angle limits for current line
    61.     Dim TempAngle As Long 'Temp to store angle
    62.     Dim AngleRandDir As Integer 'Is new angle going to have a random offset
    63.                                 'in CCW or CW direction. Ie new angle is half way
    64.                                 'between previous angles then adjusted for variance
    65.                                 'of up to 10% (AngleRand) in direction chosen by this var
    66.    
    67.     On Error Resume Next
    68.     With Picture1
    69.         .Cls 'Clear picture
    70.         .ForeColor = vbBlack 'Set forecolor
    71.         Picture1.Circle (0, 0), MaxRadius 'Draw starting circle
    72.     End With
    73.    
    74.    
    75.     'This section works out the starting points for lines in
    76.     'each new pass. So if doing 2 passes (16 lines) the first line
    77.     'in the 1st pass will be number 2 in order, the first in the
    78.     'second pass will be number 1 in order etc
    79.     '-----------------------------------------------------------------
    80.     ReDim OrderStart(1 To NumPasses)
    81.     ReDim OrderJump(1 To NumPasses)
    82.     For Loop1 = 0 To NumPasses
    83.         OrderStart(Loop1) = 2 ^ (NumPasses - Loop1) 'First line of this pass
    84.         OrderJump(Loop1) = 2 ^ (NumPasses - Loop1 + 1) 'Subsequent lines in
    85.                                         'this pass will be multiples of x
    86.     Next
    87.     '=================================================================
    88.    
    89.     'This section calcs the angles of all spokes
    90.     '-----------------------------------------------------------------
    91.     For Loop1 = 1 To NumPasses 'Loop thru number of passes
    92.         For Loop2 = 1 To 2 ^ (Loop1 + 1) 'How many NEW lines in each pass
    93.             CurrentPosn = 2 ^ (Loop1 + 1) + Loop2 'Current line
    94.             'Where this line appears in the order of all lines
    95.             Points(CurrentPosn).Order = OrderStart(Loop1) + OrderJump(Loop1) * (Loop2 - 1)
    96.            
    97.             AngleRandDir = -1 + 2 * Int(Rnd * 2) 'Get a random offset dir -1 or 1
    98.             If Loop1 = 1 Then 'First pass is diff from others because only one intermediate line
    99.                 '-----------------------------------------------------------------
    100.                 PreviousPosn = CurrentPosn - 4 'Get num of relative line in previous pass
    101.                                         'eg Line 5 is first line in pass 1. It checks
    102.                                         'Line 1 to find out the range of angles.. ie 0 to 90
    103.                 With Points(CurrentPosn) 'With the new line
    104.                     .Length = MaxRadius - Int(Rnd * LineRand) 'Random length
    105.                     .CCWAngle = 90 * (PreviousPosn - 1) 'CCW limit for next pass
    106.                     .CWAngle = 90 * PreviousPosn 'CW limit for next pass
    107.                     'Actual angle of new spoke.
    108.                     .Angle = .CCWAngle + (.CWAngle - .CCWAngle) / 2 + (.CWAngle - .CCWAngle) * (Rnd * AngleRand) / 100 * AngleRandDir
    109.                 End With
    110.                 '=================================================================
    111.             Else
    112.                 '-----------------------------------------------------------------
    113.                 PreviousPosn = (CurrentPosn + 1) \ 2 'Previous line to get angle
    114.                                     'limits from is current line divided by 2
    115.                                     'ie If on third pass lines 9 and 10
    116.                                     'use line 5 to get angle limits
    117.                 With Points(PreviousPosn)
    118.                     If CurrentPosn Mod 2 = 1 Then 'Are we creating a new line
    119.                                         'above or below the previous line
    120.                         'If above get the angle limits
    121.                         TempAngle = .CCWAngle + (.Angle - .CCWAngle) / 2 + (.Angle - .CCWAngle) * (Rnd * AngleRand) / 100 * AngleRandDir
    122.                     Else
    123.                         TempAngle = .Angle + (.CWAngle - .Angle) / 2 + (.CWAngle - .Angle) * (Rnd * AngleRand) / 100 * AngleRandDir
    124.                     End If
    125.                 End With
    126.                    
    127.                 With Points(CurrentPosn)
    128.                     .Length = MaxRadius - Int(Rnd * LineRand) 'Length of new line
    129.                     If CurrentPosn Mod 2 = 1 Then
    130.                         .CCWAngle = Points(PreviousPosn).CCWAngle
    131.                         .Angle = TempAngle
    132.                         .CWAngle = Points(PreviousPosn).Angle
    133.                     Else
    134.                         .CCWAngle = Points(PreviousPosn).Angle
    135.                         .Angle = TempAngle
    136.                         .CWAngle = Points(PreviousPosn).CWAngle
    137.                     End If
    138.                 End With
    139.                 '=================================================================
    140.             End If
    141.         Next
    142.     Next
    143.     '=================================================================
    144.    
    145.     'This section draws the actual spokes
    146.     '-----------------------------------------------------------------
    147.     For Loop1 = 1 To UBound(Points)
    148.         If Loop1 > 4 Then Picture1.ForeColor = vbBlue
    149.         With Points(Loop1)
    150.             .CurX = .Length * Cos(.Angle * (pi / 180))
    151.             .CurY = .Length * Sin(.Angle * (pi / 180))
    152.             Picture1.Line (0, 0)-(.CurX, .CurY)
    153.             PointsOrd(.Order).CurX = .CurX 'Where line is in order for connections
    154.             PointsOrd(.Order).CurY = .CurY
    155.         End With
    156.     Next
    157.     '=================================================================
    158.    
    159.     'This section draws the actual connections between spokes
    160.     '-----------------------------------------------------------------
    161.     With Points(4) 'Starting point at 360 degrees
    162.         Picture1.CurrentX = .CurX
    163.         Picture1.CurrentY = .CurY
    164.     End With
    165.    
    166.     Picture1.ForeColor = vbRed
    167.     For Loop1 = 1 To UBound(PointsOrd)
    168.         With PointsOrd(Loop1)
    169.             Picture1.Line -(.CurX, .CurY)
    170.         End With
    171.     Next
    172.     '=================================================================
    173. End Sub
    174.  
    175. 'Continued next post
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  8. #8
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    How it works:
    The number of passes determines how many lines you will draw. As an example we will use 2 passes

    So to start with we have 4 lines for the axis (1 to 4). Pass 1 adds 4 lines for the 45 deg marks (randomly offset) (5 to 8) Pass 2 adds 8 lines for 22.5 deg marks (randomly offset) (9 to 16) giving a total of 16 lines

    We also know the order of each of these lines
    ie Line1 (original axis) is at 90deg and if there are 16 lines it must be the 4th
    Line 5 (first line in pass1) is close to 45 deg and therefore must be 2nd in order
    Line 9 (first in pass2) is close to 22.5 deg and is the first line in order
    So the lines are created like this running clockwise

    Code:
    'Pass           Line Number     Order of that line
    '0              01 (90)              04
    '0              02 (180)             08
    '0              03 (270)             12
    '0              04 (360)             16
    
    '1              05 (45)              02 (4 between each in order)
    '1              06 (135)             06
    '1              07 (225)             10
    '1              08 (315)             14
    
    '2              09 (22.5)            01 '(2 between each in order)
    '2              10 (67.5)            03
    '2              11 (112.5)           05
    '2              12 (157.5)           07
    '2              13 (202.5)           09
    '2              14 (247.5)           11
    '2              15 (292.5)           13
    '2              16 (335.5)           15
    So first pass thru we create lines between 0 & 90, 90 & 180, 180 & 270, 270 & 360
    We find the half way point (ie 45) and then adjust randomly by up to 10% up or down
    Say the line becomes 42. The next pass thru would find lines (CCW) between 0 and 42 and between 42 and 90.

    'Each pass is creating a new line randomly halfway between lines of previous pass
    'The new angles are determined by the limits of the relative line in the previous pass.
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

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