Radial Sort In Line
I'd like to do a radial sort that apply an change on the first object and then increaingly all the way around till i reach the last object.
Check out the attached image to make more sense.
For example: I have an array of sphere and I'd like to change there diffuse color from white to black based on the radial array. Check out the image to make more sense. For the sake of the image i just did it by hand.
Thanks
JokerMartini
Attachment | Size |
---|---|
radialsort.png | 24.87 KB |
Comments
And another one.
The cross product didn't diffentiate vectors aligned in the same direction or in opposite directions.
this is better, thanks
it sort CCW and start from 14 (in my example .max). I modify the code and I'v got sorted CW result from 1 to 18 like this:
my recent MAXScripts RSS (archive here)
Well...
... once the objects are sorted, it's fairly trivial to shift the array and/or reverse it.
Also, this method doesn't care if the objects are in a circular pattern or not, not even if they are planar. It just sorts them by their angle as seen in the XY plane from their averaged position.
yes, nice catch
just looking for better way, nm :)
my recent MAXScripts RSS (archive here)
And another thing.
With your modification, it looks like you're now sorting the objects based on their own rotation instead of their angle from the center.
Different approach.
First a center is determined by averaging all the positions. Then the objects are sorted depending on the sense of rotation as seen from the center.
This is done in the XY plane (rotation around the Z axis).
alright
alright, ill do that. Quickly testing it is having a problem.
It's mainly just bugging out on this particular line of code.
is there an example scene that i could try testing it on that works for you?
John Martini
Digital Artist
http://www.JokerMartini.com (new site)
Ok
Attaching a scene file to test it. Note that now I see so my function return correct result only if the objects center match the origin (ie 0,0,0). I like Garp approach (at the first look) but it not return the objects in circular order. In my test scene (with 18 boxes) if they are in CW, s'd been sorted - Box01, Box02 ... Box18, and if CCW - Box01, Box18, Box17 ... Box02. Garp function looks cool but return them in order - 8, 7, 6, 5, 4, 3, 2, 1, 9, 18, 17, 16, 15, 14, 13, 12, 11, 10. Ah, and very strange but if run Garp code line by line - the result is different - start with 17, next 16, 15, ... next to the last 1 and last 18, which is correct order, just start from 17.
my recent MAXScripts RSS (archive here)
I've discovered why the error
It's erroring out because the array is empty.
I wrote this in (print sortedArray[1] and it is printing undefined.
John Martini
Digital Artist
http://www.JokerMartini.com (new site)
Hi John
I have only one hypothesis about. Because the script get itself 1st object ("at 12 o'clock"), and if it X pos is not equal to the center X pos, then the script will fail. To test if this is the issue, enter in the Listener:
objs = $Sphere* as array;dir = 1
and then execute the code in the function line by line.
my recent MAXScripts RSS (archive here)