[Closed] Sorting Adjacent
Say I have a selection of objects and I pick 2 objects “the two red objects in the left image” and then it sorts all the remaining objects into groups of adjacent objects. For the purpose of example it could just adjust wirecolor to display each level/group. The number of changes depending on the number of objects in the selection.
I’m not entirely sure how to handle the grouping properly using a threshold which would be a float value.
(
-- 1. Define Reference Objects and Selected Objects
-- 2. For each reference object collect the distances of each selected object from its center
-- 3. For each selected object loop through the collected arrays to find which distance was the lowest then index accordingly
numLeads = 2
_leadObjs = for i = 1 to numLeads collect (pickobject())
objects.wirecolor = gray
_leadObjs.wirecolor = green
clearlistener()
_trailObjs = for o in objects where (findItem _leadObjs o) == 0 collect o
_theGoods = #()
--//collect distances for all trail objects in relation to each lead object
for i = 1 to _leadObjs.count do (
local tmpArr = #()
for o = 1 to _trailObjs.count do (
append tmpArr (distance _leadObjs[i] _trailObjs[o])
)
append _theGoods tmpArr
)
)
I think he wants to have control about the intensity of the soft selection
Looking at the image say I select the two ‘starter’ objects that are red, I want to then sort the remaining objects by a threshold distance of say 10 units.
So the result returns an array of objects within a distance of 10 units from the starter objects, then another array returning the next set of objects which are within 10 units of the previous arrays objects and so forth until there are no objects left.
Hopefully the image helps.
i understood your question now.
but what you want to do is not how soft selection works.
probably the right algorithm is to sort nodes by a distance to specific point (list of points):
num = 20
size = 10
with redraw off
(
delete objects
global bb = #()
for y=0 to num-1 do for x=0 to num-1 do
(
b = box name:("b_" + formattedprint y format:"03d" + "x" + formattedprint x format:"03d") \
pos:[x*size*1.1, y*size*1.1,0] width:size length:size height:size
append bb b
)
target = bb[random 1 (num*num)] --bb[num*(num-1)/2]
select target
dd = for obj in bb collect distance obj target
dmin = amin dd
dmax = amax dd
format "% % %
" target dmin dmax
for k=1 to bb.count do bb[k].wirecolor =
(
white*(1 - (dd[k]-dmin)/(dmax-dmin))
)
)
if you want to sort nodes by distance you can use the method that i showed for sorting linked lists.
for every node collect distances to all targets, sort then and use minimum. That’s exactly how soft-selection works.
num = 20
size = 10
with redraw off
(
delete objects
global bb = #()
for y=0 to num-1 do for x=0 to num-1 do
(
b = box name:("b_" + formattedprint y format:"03d" + "x" + formattedprint x format:"03d") \
pos:[x*size*1.1, y*size*1.1,0] width:size length:size height:size
append bb b
)
targets = for k=1 to 4 collect bb[random 1 (num*num)] --bb[num*(num-1)/2]
select targets
dd = for obj in bb collect
(
tt = for target in targets collect distance obj target
amin tt
)
dmin = amin dd
dmax = amax dd
format "% % %
" target dmin dmax
for k=1 to bb.count do bb[k].wirecolor =
(
white*(1 - (dd[k]-dmin)/(dmax-dmin))
)
)
awww, nice, this is great and works perfectly. I was making it more complex than i was thinking when I was trying to conceptualize it.
Thank you Denis.
i normalize by min…max distance. soft-selection uses 0…max_limit. because i include targets in list of sources the min distance is 0.
Is that method something you just knew or was it described in the help file how the soft selection worked?