Organizing/Ordering Points for Polygon

Hello,

I wonder if you can help me. I have stumbled on finding a way to organize the points coming from “Curve.IntersectAll” from Bimorph package.

I am trying to allow the user to sketch a number of lines in any sequence. Then grab the intersecting point from the lines and finally draw a closed polygon.

You can see in the attached image the weird polygon shape…!

thanks!

Polygon1.dyn (7.5 KB)

Perhaps draw the convex hull of the collection of points, pull each point to the hull, find the parameter of each point on the hull, and use that to sort the points?

Thank you. Does that come with specific Dynamo package. How do I do that.

Hmmm…! I am after the Red boundary…

Now use a Geometry.ClosestPointTo node to find the point on the polygon from each of the original points.

Then use a Curve.PointAtParameter to provide a key to use as the sort order of the original points.

@zakim See if this and other posts on the topic below helps

1 Like

@Vikram_Subbaiah Thanks a lot, the related post is very helpful… I am getting close to to this :tired_face:, especially it works, no errors and it creates non-intersecting closed curves.
But the resulting closed curve is not what it is supposed to be…
My goal of this project is to find the correct boundary so I can calculate the closed curve area from these random interesting lines.

Sorry for he trouble… I am beginner in this new project.

Out of curiosity, why are you approaching it this way? Would it be easier to get the closest intersecting curve to each starting curve instead? What is the larger workflow for?

Hello @JacobSmall … well, may be I am not approaching correct! Or there could be a better method as you suggested.
The big picture is that these random lines represent column grids created a project which had been placed at different sequence in the project. I am simply trying to obtain the intersecting points between the lines, so I can calculate the closed curve area from these random intersecting lines.

I wonder if you have a resource or sample to the “closest intersecting curve” method.

Thanks

Hmmm… can you share the lines as you currently have them? Have a few ideas with this larger goal in mind, but they may not pan out.

I’m not using my work CPU today (holiday), so no Revit or Dynamo playtime on stuff like this for at least 24 hours, but someone else might be able to help out and provide an idea once you post those files.

Thanks @JacobSmall … and I appreciate you all looking and helping me with this. I totally understand and here are attached the Revit + Dynamo Graph attempts.

ForumSample.rvt (352 KB)

Polygon2JacobSmallMethod.dyn (13.7 KB)
Polygon2VikramMethod.dyn (9.8 KB)

Hi All,

I have modified the graph. One good thing is:
1) It looks like I can grab “All other Line segments” with their Start/End point of each segment as a result of “Geometry.DoesIntersect” method. But How can I can I create a line from each sub-list?
2) There is also the last closing segment unique start and end point shown in the list. Which is great, but how can I grab them as unique two items to draw a closing line segment.

Well… Here is another attempt… I hit a wall and stumbled closing this last segment … any thoughts how to override the loop!

What is the outcome of the final List.Map node? Might be better to use a Line.ByBestFitThrougjPoints (or even a Curve.SplitByPoints node then taking the even segments) and then use a Polycurve.ByJoinedCurves node to join them into one.

Hi @JacobSmall … here is the outcome of the final List.Map. I am just unable/stuck to filter the last segment line that contains the start/end points.

Are there one or two points in the prior list map at this relative index?

There are two points.

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

Don’t think that approach would take you further though :neutral_face:

This should …


trimCurvesSequence.dyn (31.5 KB)

9 Likes

Thank you all @c.poupin @JacobSmall @Vikram_Subbaiah for helping me with this… really appreciate it.
I am not familiar with Python and the code block… it is way on top of my head :slight_smile: and need to understand these different parts of code.
I want to try it and let you know.
Thanks a lot. :pray:

2 Likes