Guest User

Untitled

a guest
Jul 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.42 KB | None | 0 0
  1. 'Sub Macro1()
  2. '
  3. ' Macro1 Macro
  4. '
  5.  
  6. '
  7. '    Range("B1").Select
  8. 'End Sub
  9.  
  10. Option Base 1
  11.  
  12. Private Sub circlegen()
  13.  
  14. Dim r As Integer    'radius value
  15. Dim xc As Integer   'circle center x value
  16. Dim yc As Integer   'circle center y value
  17. Dim x As Integer    'circle pixel x value
  18. Dim y As Integer    'circle pixel y value
  19. Dim d As Integer    'discriminant value for determining proximity to locus
  20. Dim dtest As Integer
  21. Dim i1 As Integer   'counter 1
  22. Dim i2 As Integer   'counter 2
  23. Dim iA As Integer   'circle coord array X coord element counter
  24. Dim iB As Integer   'circle coord array Y coord element counter
  25. Dim ar_oct_x()
  26. Dim ar_oct_y()
  27. Dim ar_circle()
  28.  
  29.  
  30.  
  31. 'get seed values from input cells
  32. r = Cells.Range("B1").Value
  33. xc = Cells.Range("B2").Value
  34. yc = Cells.Range("B3").Value
  35.  
  36.  
  37. 'populate seed octant x and y coordinate arrays
  38. 'plot first point for clockwise movement and d value
  39. x = 0
  40. y = r
  41. d = (5 - (r * 4)) / 4
  42.  
  43. i1 = 1  'initialize counter 1
  44. Do Until x > y 'when x > y, then the midpoint pixel shared by octants has been reached
  45.     'populate array
  46.         ReDim Preserve ar_oct_x(i1)
  47.             ar_oct_x(i1) = x
  48.         'y coord
  49.         ReDim Preserve ar_oct_y(i1)
  50.             ar_oct_y(i1) = y
  51.         'increment counter
  52.         i1 = i1 + 1
  53.  
  54.     x = x + 1
  55.     If d < 0 Then
  56.         d = d + (2 * x + 1)
  57.     Else
  58.         y = y - 1
  59.         d = d + (2 * (x - y) + 1)
  60.     End If
  61. Loop
  62.  
  63. 'populate final coordinate array with translated octant values
  64. ReDim ar_circle(1 To 2, 1 To i1 * 8)
  65.  
  66. iA = 1
  67. iB = 1
  68. For i2 = 1 To UBound(ar_oct_x, 2)
  69.     'cardinal coordinates
  70.     If ar_oct_x(i2) = 0 Then
  71.         'N
  72.         ar_circle(iA, iB) = ar_oct_x(i2)
  73.             iB = iB + 1
  74.         ar_circle(iA, iB) = ar_oct_y(i2)
  75.             iA = iA + 1
  76.             iB = iB - 1
  77.         'S
  78.         ar_circle(iA, iB) = ar_oct_x(i2)
  79.             iB = iB + 1
  80.         ar_circle(iA, iB) = -(ar_oct_y(i2))
  81.             iA = iA + 1
  82.             iB = iB - 1
  83.         'E
  84.         ar_circle(iA, iB) = ar_oct_y(i2)
  85.             iB = iB + 1
  86.         ar_circle(iA, iB) = ar_oct_x(i2)
  87.             iA = iA + 1
  88.             iB = iB - 1
  89.         'W
  90.         ar_circle(iA, iB) = -(ar_oct_y(i2))
  91.             iB = iB + 1
  92.         ar_circle(iA, iB) = ar_oct_x(i2)
  93.             iA = iA + 1
  94.             iB = iB - 1
  95.     End If
  96.    
  97.     'Ordinal coordinates
  98.     If ar_oct_x(i2) = ar_oct_y(i2) Then
  99.        
  100.     End If
  101. Next
  102.  
  103.  
  104. dtest = 1
  105.  
  106. End Sub
Add Comment
Please, Sign In to add comment