PDA

View Full Version : Equivalent of Maya's min() & max()?


ACFred
02-25-2009, 10:46 PM
Anything like Maya's MEL min() & max() functions exist in maxscript?
If unfamiliar with them, min() & max() return the small of two numbers (min) or the larger of two numbers (max).

I can obviously write the simple function to do the same thing, but I'm just wondering if it already exists somewhere and I just missed it.

Thanks,

Alec

Bobo
02-25-2009, 10:52 PM
Anything like Maya's MEL min() & max() functions exist in maxscript?
If unfamiliar with them, min() & max() return the small of two numbers (min) or the larger of two numbers (max).

I can obviously write the simple function to do the same thing, but I'm just wondering if it already exists somewhere and I just missed it.

Thanks,

Alec

The equivalent in MAXScript is amin() and amax(). The 'a' is for 'array' and you pass the values to test as array. The result is the min or max value of all values in the array.

For example,

amin #(10,20.3,1.1,15)
--> 1.1
amax #(10,20.3,1.1,15)
--> 20.3

The beauty of this method is that it works on any array whose values can be compared.
For example

amin #("bobo","test","ah!","oh!")
-->"ah!"
amax #("bobo","test","ah!","oh!")
-->"test"

which is equivalent to

theArray = #("bobo","test","ah!","oh!")
(sort theArray)[1]
(sort theArray)[theArray.count]

ACFred
02-25-2009, 11:00 PM
Cool. Slightly embarrassing it was right there.
Thanks for the help.

What about an equivalent for linstep and smoothstep?

Thanks again,

Alec

magicm
02-25-2009, 11:53 PM
Just a note, you can also do something like
amin 0 10
0
amax 0 10
10
so you could combine both methods to 'clamp' a number (eg. between -4 and 13):
myVal = 16
16
myVal = amax -4 (amin 13 myVal)
13
myVal = -50
16
myVal = amax -4 (amin 13 myVal)
-4
Cheers,
Martijn

CGTalk Moderation
02-25-2009, 11:53 PM
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.