Notifications
Clear all
[Closed] Add to points
Mar 07, 2013 9:22 pm
My brain hurts and I may need a bit of help with the structure of this one.
I want to build an array of 300 points
- lets start out with one point randomly within a volume say 100x100x100
- until we reach 3oo points create 10 points in the same volume
- sort these 10 points and test against the existing point in the final array and select the one point with the largest distance from all the final points.
- add the largest to the array, discard the other 9
5.wash and repeat
Sounds super simple but id love to see the most compact form possible cause i don’t have it working yet. Any help would be great.
Thanks!
-Michael
1 Reply
Mar 07, 2013 9:22 pm
You seem to like O(n^2) solutions Only wanted to have a look what’s new around here as I’m coping with illness but I just couldn’t resist to give you what you asked for even though it’s most probably not what you actually wanted:
(
local maximum = [50,50,50]
local minimum = -maximum
local points = #()
fn compareVal v1 v2 =
if v1 > v2 then 1
else if v2 < v2 then -1
else 0
fn compareDistMedian p1 p2 =
(
local d1 = for p in points collect distance p p1
local d2 = for p in points collect distance p p2
compareVal (sort d1)[d1.count/2+1] (sort d2)[d2.count/2+1]
)
append points (random minimum maximum)
while points.count < 300 do
(
local batch = for i = 1 to 10 collect (random minimum maximum)
qsort batch compareDistMedian
append points batch[1]
)
for p in points do Point pos:p
)
By the way, is particle system fun strictly forbidden?
(
local emitter = pCloud formation:0 quantityMethod:1 total_number:300 viewPercent:100 \
Emitter_Rad_Len:100 Emitter_Width:100 Emitter_Height:100 \
seed:(random 0 1e6) isHidden:true
for i = 1 to 300 do Point pos:(particlePos emitter i)
delete emitter
)