That is very true, The spiral affect is the way the actual web works. That is something I can look into, make it spiral when it webs. I’ve gotta get the radial sorting corrected first. I messaged ya about it to see if you could see if you noticed anything wrong.
And how to force ParticeFlow to think like a spider and produce beautiful sticky web?
The spider math is more advanced then PF code
This seems to sort in a radial fashion a bit better.
Especially things that are no perfectly on the x,y.
(
local theObjects = getCurrentSelection()
local count = theObjects.count
local center = [0, 0, 0]
for obj in theObjects do center += obj.pos
center /= count
fn angularSort obj1 obj2 = (
in coordSys (transMatrix center)
obj1[3][2][3].value - obj2[3][2][3].value
)
-- create points (in case the objects has not Z_Rotation controller)
tmpPoints = for obj in theObjects collect
Point pos:obj.pos name:(obj.name+"_")
qsort tmpPoints angularSort
sortedArray = #(); sortedArray.count = theObjects.count
for i = 1 to tmpPoints.count do (
sortedArray[i] = getNodeByName (trimRight tmpPoints[i].name "_")
)
delete tmpPoints
print sortedArray
for o = 1 to sortedArray.count do sortedArray[o].wirecolor = [0,20*o,20*o]
)
Better Way?
Is there a better way of doing this? Without having to create the point helpers.
Radial Sorting?
local center = [0, 0, 0]
fn angularSort pt1 pt2 = (
in coordSys (transMatrix center)
pt1[3][2][3].value - pt2[3][2][3].value
)
fn fnRadialSortPoints arr = (
local count = arr.count
for pt in arr do center += pt
center /= count
-- Create points (in case the objects has not Z_Rotation controller)
tmpPoints = for pt in arr collect Point pos:pt
qsort tmpPoints angularSort
delete tmpPoints
)
fnRadialSortPoints tmpPoints
ive attached a file for testing on. In the file you’ll see a spline was drawn. That is there to represent the radial sorting.
I’m looking for some help on sorting position in 3d space in a radial array.
This works. Pick a point helper (any) and run the code
First next point will be one that is closer to the selected point
fn RemoveItemFromArray arr itm =
(
local idx = findItem arr itm
if idx == 0 then false else deleteItem arr idx
)
pointArr = $Point* as array
if selection.count == 1 do
(
posArr = #(selection[1].center)
itm = selection[1]
while pointArr.count != 1 do
(
minDist = amin (for p in pointArr where p != itm collect distance itm.center p.center)
format "minDist = %
" minDist
nextnode = (for p in pointArr where p != itm and (distance itm.center p.center) == minDist collect p)[1]
pointArr = RemoveItemFromArray pointArr itm
itm = nextnode ; append posArr itm.center
)
format "posArr = %
" posArr
)
So in order to get the radial web sorting to be correct this is what i need to figure out.
I need to return an array which is the order of splines in a shape, but in order based on the radial sorting of the first knot in each spline.
delete objects
struct ThePoint (index, pos, angle, polar)
points = for k=1 to 16 collect
(
a = random 0 360
p = [(cos a)*(random 5 20), (sin a)*(random 5 20), random -20 20]
ThePoint index:k pos:p
)
fn sortByPolar p1 p2 = if p1.polar < p2.polar then -1 else if p1.polar > p2.polar then 1 else 0
fn sortByAngle p1 p2 = if p1.angle < p2.angle then -1 else if p1.angle > p2.angle then 1 else sortByPolar p1 p2
fn tangent x y =
(
ang = atan ((y as float)/x)
if x < 0 do ang += 180
if x > 0 and y < 0 do ang += 360
360 - ang
)
fn polarAngleSort points center: tm:(matrix3 1) =
(
if points.count > 1 then
(
if center == unsupplied do
(
center = [0,0,0]
for p in points do center += p.pos
center /= points.count
center *= tm
)
tm = translate (tm.rotation as matrix3) center
for p in points do
(
pos = p.pos * tm
p.polar = pos.z
pos = normalize pos
p.angle = tangent pos.x pos.y
)
qsort points sortByAngle
points
)
else points
)
polarAngleSort points
for k=1 to points.count do
(
in (point pos:points[k].pos size:0.5 wirecolor:yellow)
text pos:(points[k].pos+[0,0,0]) text:(k as string + " - " + points[k].index as string) size:1 wirecolor:yellow
)
This solution are amazing.
Denis can you explain last for-loop. (First time I saw “in” in MXS.)
see in context in mxs help. it’s very old technique. the new generation of mxs scripters doesn’t use it any more. but i as an old school guy still do.
Another update. With a handful of new features and whatnot. It does all sorts of new things.
to sort ends of a web rays you have to feed the algorithm with center of the web and its coordinate system (technically the local coordinate system might be made using Average Normal of the web).