title: (VBA, Excel) Sort Wall Points Clockwise Starting at an Arbitrary Point
body: <p>I'm new here and am also relatively new to VBA. I've been struggling with this problem for a while and can't seem to find a solution. 
  I have points that correspond to either endpoint of a wall or intersections of a wall (Shown in an attached image).</p>
  
  <p><a href="https://i.stack.imgur.com/7z9CR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7z9CR.png" alt="Points"></a></p>
  
  <pre><code>enter code here
  </code></pre>
  
  <p>I need to turn this information into points along the wall boundary (from a given wall thickness) sorted in a clockwise manner from an arbitrary point. See the attached image.</p>
  
  <p><a href="https://i.stack.imgur.com/mdnhI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mdnhI.png" alt="Goal"></a></p>
  
  <p>I've managed to create points at boundaries (very roughly) by shrinking back each node by half of the wall thickness and then moving each resulting node "side to side" in the perpendicular direction by half of the wall thickness.</p>
  
  <p>The data I have does show node pairs for each line. These "AtoB" line type connection pairs exist node to node and don't overlap of the cross.<br/>
  Any suggestions or help would be greatly appreciated. I'm a bit stuck.
  Thanks!
  J </p>
  
  <p>Below is output information for an "L" shaped wall:
  <a href="https://i.stack.imgur.com/lA4Hb.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>I then take the XY coordinates and shift them:</p>
  
  <pre><code>ReDim CoordsArr(9, 3) '10 Walls total available per pier
  
  ''' Store coord in variables '''
  For coordrow = 0 To Counter - 2
  CoordsArr(coordrow, 0) = Cells(24 + coordrow, 5)
  CoordsArr(coordrow, 1) = Cells(24 + coordrow, 6)
  CoordsArr(coordrow, 2) = Cells(24 + coordrow, 8)
  CoordsArr(coordrow, 3) = Cells(24 + coordrow, 9)
  Next coordrow
  ''' Generate New Corner Points '''
  ReDim POINTS_XY(19, 7) 'Array as (x1,y1,x2,y2,x3,y3,x4,y4) for points 
  'above and below CL
  For coordrow = 0 To Counter - 2
  If Abs(CoordsArr(coordrow, 3) - CoordsArr(coordrow, 1)) = 0 Then
  If CoordsArr(coordrow, 0) &lt; CoordsArr(coordrow, 2) Then
  XnewL = CoordsArr(coordrow, 0) + thick / 2
  XnewR = CoordsArr(coordrow, 2) - thick / 2
  POINTS_XY(coordrow, 0) = XnewL
  POINTS_XY(coordrow, 1) = thick / 2
  POINTS_XY(coordrow, 2) = XnewL
  POINTS_XY(coordrow, 3) = -thick / 2
  POINTS_XY(coordrow, 4) = XnewR
  POINTS_XY(coordrow, 5) = thick / 2
  POINTS_XY(coordrow, 6) = XnewR
  POINTS_XY(coordrow, 7) = -thick / 2
  ElseIf CoordsArr(coordrow, 0) &gt; CoordsArr(coordrow, 2) Then
  XnewL = CoordsArr(coordrow, 0) - thick / 2
  XnewR = CoordsArr(coordrow, 2) + thick / 2
  POINTS_XY(coordrow, 0) = XnewL
  POINTS_XY(coordrow, 1) = thick / 2
  POINTS_XY(coordrow, 2) = XnewL
  POINTS_XY(coordrow, 3) = -thick / 2
  POINTS_XY(coordrow, 4) = XnewR
  POINTS_XY(coordrow, 5) = thick / 2
  POINTS_XY(coordrow, 6) = XnewR
  POINTS_XY(coordrow, 7) = -thick / 2
  End If
  ElseIf Abs(CoordsArr(coordrow, 2) - CoordsArr(coordrow, 0)) = 0 Then
  If CoordsArr(coordrow, 1) &lt; CoordsArr(coordrow, 3) Then
  YnewD = CoordsArr(coordrow, 1) + thick / 2
  YnewU = CoordsArr(coordrow, 3) - thick / 2
  POINTS_XY(coordrow, 0) = -thick / 2
  POINTS_XY(coordrow, 1) = YnewD
  POINTS_XY(coordrow, 2) = thick / 2
  POINTS_XY(coordrow, 3) = YnewD
  POINTS_XY(coordrow, 4) = -thick / 2
  POINTS_XY(coordrow, 5) = YnewU
  POINTS_XY(coordrow, 6) = thick / 2
  POINTS_XY(coordrow, 7) = YnewU
  ElseIf CoordsArr(coordrow, 1) &gt; CoordsArr(coordrow, 3) Then
  YnewD = CoordsArr(coordrow, 1) - thick / 2
  YnewU = CoordsArr(coordrow, 3) + thick / 2
  POINTS_XY(coordrow, 0) = -thick / 2
  POINTS_XY(coordrow, 1) = YnewD
  POINTS_XY(coordrow, 2) = thick / 2
  POINTS_XY(coordrow, 3) = YnewD
  POINTS_XY(coordrow, 4) = -thick / 2
  POINTS_XY(coordrow, 5) = YnewU
  POINTS_XY(coordrow, 6) = thick / 2
  POINTS_XY(coordrow, 7) = YnewU
  End If
  End If
  Next coordrow
  </code></pre>