Organizing/Ordering Points for Polygon

Hello
a solution with Python should be work in most case

sortedpointforpolygon

import sys
import clr
import itertools
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

def customIntersectAll(*args):
	for curveA, curveB in itertools.product(*args):
		interSet = curveA.Intersect(curveB)
		for i in interSet:
			if isinstance(i, Point) and 0.02 < curveA.ParameterAtPoint(i) < 0.98:
				yield(i)
				
def sortPoint(lstPts, orderPts = []):
	global lstCurveA
	if len(orderPts) == 0:
		orderPts.append(lstPts.pop(0))
	#	
	lstPts.sort(key = lambda x : x.DistanceTo(orderPts[-1]))
	for idx, pta in enumerate(lstPts):
		lineAB = Line.ByStartPointEndPoint(pta, orderPts[-1])
		if any(len(lineAB.Intersect(x)) > 0 and isinstance(lineAB.Intersect(x)[0], Line) for x in lstCurveA):
			orderPts.append(lstPts.pop(idx))
			return sortPoint(lstPts, orderPts)
	return orderPts
			
lstCurveA = IN[0]
lstCurveB = lstCurveA[:]
outPoint = []
for pt in customIntersectAll( lstCurveA, lstCurveB):
	if all(not pt.IsAlmostEqualTo(x) for x in outPoint):
		outPoint.append(pt)
		
OUT = sortPoint(outPoint) 		

see also this post
Organizing/Ordering Points for Polygon - #27 by c.poupin

9 Likes