PDA

View Full Version : Select Maximum Height?

 Somakai01-17-2008, 07:27 PMI'm feelin' pretty dense right now - Is this simple or what? Is it at all possible to select the tallest from a group of boxes with randomly generated heights? Sounds simple, but I've not been able to figure it out. I've written a script that generates a field of boxes with a default height & a probability factor for each box to deviate from this height - I would like, upon each iteration of the script for the default height to be replaced by the tallest of the group, to yield an ever-escalating group of mutating boxes. The # of boxes is variable & infinite, so I need a wildcard "select \$Box*.height maximum" - type deal. Thanks for your help..
focomoso
01-17-2008, 08:17 PM
amax (for b in \$Box* collect b.height) -- but it would be faster to keep track of the tallest one while you create the boxes

Somakai
01-17-2008, 09:11 PM
holy crap; you're a lifesaver..

but what exactly do you mean "keep track of the tallest one while you create the boxes"?

efficiency is of upmost importance here, as this script will be used to generate mass quantities of these little boxes.

as it stands the code is as follows:

ggm = 3 -- Define grid maximum
gmp = 85 -- Define global mutation probability
gdh = 12 -- Define default seed height
gml = -6.0 -- Define minimum mutation step
gmh = 6.0 -- Define maximum mutation step

-- Delete current boxes
if \$Box* != undefined
then delete \$Box*

for gi = 0 to ggm-1 do

(
-- Define global seed
if lrh != undefined
then dgs = lrh
else dgs = gdh

for li = 0 to ggm-1 do

(
lgr = random 1 100
lpr = random gml gmh
if lgr > gmp
then lrv = dgs + lpr
else lrv = dgs
Si = box length: 12 width: 12 height: lrv
Si.pos = [gi*36,li*36,0]
)
)
lrh = amax (for b in \$Box* collect b.height)

Seems pretty fast - I'm able to run through about 3 iterations a second with a field of ten boxes without slowing down on a 2.4Ghz P4.

I'm a beginner at Maxscript, obviously, though & don't know much about increasing the efficiency of a script.

I really appreciate you helpin' me out..

RustyKnight
01-17-2008, 10:03 PM
I believe what focomoso is saying, is that when you create the box, you will want to maintain a reference to the heights box's height...

Si = box length: 12 width: 12 height: lrv
if lrv > maxHeight do maxHeight = lrv
This would probably be quicker then trying to loop through all the objects AGAIN to determine the heighest box.

Although I have to say, focomoso approach is rather cool

Shane

drdubosc
01-17-2008, 10:40 PM
I believe what focomoso is saying, is that when you create the box, you will want to maintain a reference to the heights box's height...

Si = box length: 12 width: 12 height: lrv
if lrv > maxHeight do maxHeight = lrv
This would probably be quicker then trying to loop through all the objects AGAIN to determine the heighest box.

Although I have to say, focomoso approach is rather cool

Shane

.. and if you're being really picky, you would insert it here:

.
.
if lgr > gmp
then (
lrv = dgs + lpr
if lrv > maxHeight do maxHeight = lrv
)
else lrv = dgs
.
.

eliminating 85% of your comparisons, on average?

RustyKnight
01-17-2008, 11:09 PM
nice catch!

focomoso
01-18-2008, 05:05 AM
I believe what focomoso is saying, is that when you create the box, you will want to maintain a reference to the heights box's height...
That's exactly what I was saying.

Although I have to say, focomoso approach is rather cool
Thanks, I thought so myself:)

Somakai
01-18-2008, 05:45 AM
wow, you guys are insane - thanks a million

.. and if you're being really picky, you would insert it here:

Code:

.
.
if lgr > gmp
then (
lrv = dgs + lpr
if lrv > maxHeight do maxHeight = lrv
)
else lrv = dgs
.
.

eliminating 85% of your comparisons, on average?

hmm.. but I don't seem to get a return.
I'll look more into it - thanks, peoples..

drdubosc
01-18-2008, 10:48 AM
Edit: I was wrong anyway .. hadn't taken into account the possibility that no mutations happened at all, or all mutated negative.

CGTalk Moderation
01-18-2008, 10:48 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.