Notifications
Clear all

[Closed] Qsort???

Here’s my quick stab at it… but I’ve found a issue with my angle idea… that the distance is a factor for closely angled points… so I was thinking maybe a line intersect for point within a certain angle threshold to see if they need to be swapped as well… Or perhaps another approch all together…


 (
 fn Qsort_LargestZ V1 V2 = 
 	(
 	case of
 		(
 		(v1.z > v2.z):( Return 1 )
 		(v1.z < v2.z):( Return -1 )
 		default:(Return 0)
 		)
 	)
 -- create Array and define center... visually.. 
 -- use .z value of point three var to hold angle
 local PointArray = #()
 local Angle = 0.0
 
 -- QuadOffset value is greater than the largest potential negative value per x and y
 -- can be dynamically found in array, for ease I've set it
 -- ensures all Atan2 calulations occure in the same qaudrent.. the one we all love qaudrent 1
 local QuadOffset = [ 200, 200, 0]
 
 -- clear last run from screen
 Delete $'Point*'
 -- make array and visual reference
 for i=1 to 30 do	
 	(
 	tnPoint = (Point pos:[(random -100 100),(random -100 100),0])
 	append PointArray [tnPoint.pos.x, tnPoint.pos.y, Angle ]
 	)
 -- pick a point
 tnPoint = PickObject prompt:"Pick At Point"
 -- delete Selected Item from Point Array
 deleteitem PointArray ( findItem PointArray [tnPoint.pos.x, tnPoint.pos.y,0] )
 -- define Center Point
 CenterPoint = [tnPoint.pos.x, tnPoint.pos.y, -1 ] + QuadOffset
 
 for chkPoint in PointArray do
 	(
 -- compute angle for all points 
 	tnAn = atan2 ( centerPoint.x - ( ChkPoint.x + QuadOffset.x) ) ( CenterPoint.y - ( ChkPoint.y + QuadOffset.y ) )		
 	ChkPoint.z = (tnAN + 180)
 	)
 
 qsort PointArray Qsort_LargestZ
 
 tnSpline = SplineShape name:"Point_Drawn_Spline" wirecolor:Yellow
 addNewSpline tnSpline
 
 for chkPoint in PointArray do
 	(
 	if ( chkPoint.z != -1 ) then
 		addKnot tnSpline 1 #smooth #curve [chkPoint.x,chkPoint.y,0]
 	format "%
" chkPoint
 	)
 close tnSpline 1 
 updateShape tnSpline
 )
 

Well it makes fun shapes…

Good luck

Page 2 / 2