Notifications
Clear all

[Closed] Select Maximum Height?

I’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…

8 Replies

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

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…

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

2 Replies
(@drdubosc)
Joined: 11 months ago

Posts: 0

… 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?

(@focomoso)
Joined: 11 months ago

Posts: 0

That’s exactly what I was saying.

Although I have to say, focomoso approach is rather cool

Thanks, I thought so myself:)

nice catch!

wow, you guys are insane – thanks a million

… and if you’re being really picky, you would insert it here:

  Code:

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

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…

Edit: I was wrong anyway … hadn’t taken into account the possibility that no mutations happened at all, or all mutated negative.