How can I get a Min/Max clamp for any form of math, integrals, nominal, etc?
I know there is Component clamp for shaders, but I can't seem to use it for simple chunks of numbers.
Math Clamp node - Request - solved
- Draise
- Captain
- Posts: 3198
- Joined: 21 Sep 2009, 19:33
- Type the number ten into the box: 0
- Location: Bogota, Colombia
- Contact:
Math Clamp node - Request - solved
Last edited by Draise on 10 Sep 2012, 03:41, edited 1 time in total.
- Draise
- Captain
- Posts: 3198
- Joined: 21 Sep 2009, 19:33
- Type the number ten into the box: 0
- Location: Bogota, Colombia
- Contact:
Re: Math Clamp node - Request
Code: Select all
// this one-liner is good to know:
// Math.max(minValue, Math.min(maxValue, valueToClamp));
// wrapped in a function it looks like this:
const MIN:Number = 0;
const MAX:Number = 100;
function clamp(val:Number, min:Number = MIN, max:Number = MAX){
return Math.max(min, Math.min(max, val))
}
for (var i:int = 0; i<1000; i++){
var val:Number = Math.random()*1000 - 500;
// clamp the above random value between -100 and +100
trace(clamp(val, -100, 100));
}
Or this one:
Code: Select all
/**
* Returns a number whose value is limited to the given range.
*
* Example: limit the output of this computation to between 0 and 255
* (x * 255).clamp(0, 255)
*
* @param {Number} min The lower boundary of the output range
* @param {Number} max The upper boundary of the output range
* @returns A number in the range [min, max]
* @type Number
*/
Number.prototype.clamp = function(min, max) {
return Math.min(Math.max(this, min), max);
};
- Draise
- Captain
- Posts: 3198
- Joined: 21 Sep 2009, 19:33
- Type the number ten into the box: 0
- Location: Bogota, Colombia
- Contact:
Re: Math Clamp node - Request
Ah, don't worry. Found a node in the Smart Sphere that has a Min/Max clamp plus a scale that deals with what I needed. Perfect. Exactly what I needed!
It is the Transform node located in the Smart Sphere.
I have attached it, in-case it will come in handy for others.
It is the Transform node located in the Smart Sphere.
I have attached it, in-case it will come in handy for others.
You do not have the required permissions to view the files attached to this post.