Find outermost points & sort

Find outermost points & sort

llorden4
Collaborator Collaborator
552 Views
3 Replies
Message 1 of 4

Find outermost points & sort

llorden4
Collaborator
Collaborator

I'm attempting a sort that's currently above my skill level and hoping someone might be willing to help me solve this task.  I have a group of faces I'm attempting to evaluate from an unfold pattern in prep for some additional features to be added to assist with production.  I've got the majority of the routine figured out, the only obstacle I have left is to get the outermost points of each face identified and located in an array friendly to my developed routine.

 

I have been able to make a list of every edge start/stop point (converted to the planar sketch 2D point) without duplicating points (basically a list of each point on the face) but now need to sort this collection into my desired 4 point array where...

Point({face#}, 1) = bottom left 2D point

Point({face#}, 2) = top left 2D point

Point({face#}, 3) = top right 2D point

Point({face#}, 4) = bottom right 2D point

llorden4_1-1642431928438.png

 

This image shows some of the feature challenges I have with each face.  I'll have a minimum of 4 points on each varying UCS sketch plane, but can easily have more than that.  Each face orientation varies from the other.

 

I've attempted to use relative position to each of the points against each other as well as a "PointOnFace" to create a polarized X,Y result to form a quadrant based result; but this has proved to be unreliable.  I'm hoping someone might have some insight they might share on solving such a problem or know of an easier way to tackle this.

 

Autodesk Inventor Certified Professional
0 Likes
Accepted solutions (1)
553 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Would you be able to use the SketchPoint.ReferencedEntity to get the model geometry it was based on, then maybe check some Attribute or ReferenceKey or other uniquely identifying aspect of that model geometry to determine which point is which?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

llorden4
Collaborator
Collaborator

I see where you're thinking and don't think that will work.  The flats are generated using a loft of two open profiles, the ends then sliced to a desired angle and user features then possibly added.  None of the original design points would likely remain and the face is a result of the remaining untrimmed features.  

Autodesk Inventor Certified Professional
0 Likes
Message 4 of 4

llorden4
Collaborator
Collaborator
Accepted solution

I have come up with a routine that handles the majority of cases, I do expect to see issues when there are user cutouts and will just have to require those be manually developed until I can come up with something better.  Since I asked for solutions, seems only fair I share mine; perhaps someone can provide a more elegant solution than this.  Here's the gist of the code, it does not contain all necessary declarations and will need expected model data to function so don't expect to be able to copy, paste & run.

 

Dim oMin As Double
Dim oMax As Double
Dim oStart() As Double = {}
Dim oEnd() As Double = {}
Dim PointList As New ArrayList
Dim LeftList As New ArrayList
Dim RightList As New ArrayList
Dim MinX As Double
Dim MaxX As Double
Dim MinY As Double
Dim MaxY As Double
Dim MidBox As Point2d
Dim NoSides As Integer = 6
Dim NoSections As Integer = 2
Dim StartFlat As Integer = 1

For i = 1 To NoSides / NoSections												'collect faces into array
	oFaceColl(i) = iLogicVb.Automation.GetNamedEntities(ThisDoc.Document).TryGetEntity("Flat " & CStr(i + StartFlat - 1))
	PointList.Clear
	LeftList.Clear
	RightList.Clear
	For j = 1 To oFaceColl(i).Edges.Count										'set loop for each edge found
		oFaceColl(i).Edges.Item(j).Evaluator.GetEndPoints(oStart, oEnd)
		oPntChk(1) = oTG.CreatePoint(oStart(0), oStart(1), oStart(2))			'get start point of current edge
		oPntChk(2) = oTG.CreatePoint(oEnd(0), oEnd(1), oEnd(2))					'get endpoint of current edge
		oChkPnt(1) = oSketch.ModelToSketchSpace(oPntChk(1))						'convert to sketch 2d
		oChkPnt(2) = oSketch.ModelToSketchSpace(oPntChk(2))						'convert to sketch 2d
		For k = 1 To 2
			Found = False
			For l = 1 To PointList.Count
				If oChkPnt(k).IsEqualTo(PointList.Item(l - 1)) Then Found = True
			Next
			If Not Found Then PointList.Add(oChkPnt(k))							'add non-duplicated points to list
		Next
	Next
	'sort points
	MinX = PointList.Item(0).X
	MaxX = PointList.Item(0).X
	MinY = PointList.Item(0).Y
	MaxY = PointList.Item(0).Y
	Dim FPoint(NoSides / NoSections, 4)
	For j = 1 To PointList.Count - 1													'find extents box of 2D point list
		If PointList.Item(j).X < MinX Then MinX = PointList.Item(j).X
		If PointList.Item(j).X > MaxX Then MaxX = PointList.Item(j).X
		If PointList.Item(j).Y < MinY Then MinY = PointList.Item(j).Y
		If PointList.Item(j).Y > MaxY Then MaxY = PointList.Item(j).Y
	Next
	MidBox = oTG.CreatePoint2d(MaxX - ((MaxX - MinX) / 2), MaxY - ((MaxY - MinY) / 2))	'Approximate middle of face
	'Sort into left/right sides (along x axis)
	For j = 0 To PointList.Count - 1
		If PointList.Item(j).X < MidBox.X Then LeftList.Add(PointList.Item(j)) Else RightList.Add(PointList.Item(j))
	Next
	'Left side sort
	If LeftList.Count = 2 Then
		If LeftList.Item(0).Y < LeftList.Item(1).Y Then
			FPoint(i, 1) = LeftList.Item(0)
			FPoint(i, 2) = LeftList.Item(1)
		Else
			FPoint(i, 2) = LeftList.Item(0)
			FPoint(i, 1) = LeftList.Item(1)
		End If
	Else
		For j = 0 To LeftList.Count - 1
			If LeftList.Item(j).Y = MinY Then
				FPoint(i, 1) = LeftList.Item(j)			'find point a min Y position & assign as lower left point
				LeftList.RemoveAt(j)					'remove from current list
				Exit For								'found it, exit loop
			End If
		Next
		FPoint(i, 2) = LeftList.Item(0)					'temp assign first point in updated list
		For j = 1 To LeftList.Count - 1					'search for left most X position
			If LeftList.Item(j).Y > FPoint(i, 2).Y Then FPoint(i, 2) = LeftList.Item(j)
		Next
	End If
	'Right side sort
	If RightList.Count = 2 Then
		If RightList.Item(0).Y > RightList.Item(1).Y Then
			FPoint(i, 3) = RightList.Item(0)
			FPoint(i, 4) = RightList.Item(1)
		Else
			FPoint(i, 4) = RightList.Item(0)
			FPoint(i, 3) = RightList.Item(1)
		End If
	Else
		For j = 0 To RightList.Count - 1
			If RightList.Item(j).Y = MaxY Then
				FPoint(i, 3) = RightList.Item(j)		'find point a max Y position & assign as lower left point
				RightList.RemoveAt(j)					'remove from current list
				Exit For								'found it, exit loop
			End If
		Next
		FPoint(i, 4) = RightList.Item(0)					'temp assign first point in updated list
		For j = 1 To RightList.Count - 1					'search for right most X position
			If RightList.Item(j).X > FPoint(i, 4).X Then FPoint(i, 4) = RightList.Item(j)
		Next
	End If

	For j = 1 To 4
		oSketch.SketchPoints.Add(FPoint(i, j))
	Next

Next 

 

Autodesk Inventor Certified Professional
0 Likes