TLH14
Member
I'm pretty sure I get the basic function behind clamp. If I were to script it out myself, I'd do something along the lines of...
However, that's just the basic logic behind clamp and is not necessarily everything going on in the function; I have no idea how things are running under the hood to make the function perform as it does, that's simply my interpretation. All I've found from searching the internet is answers explaining the basic functionality behind clamp, not anything more specific or advanced.
Why I ask is because I want to create scripts similar to clamp...
These are my interpretations on how to go about the functions I want, but I don't really know if they're the most efficient way to go about things, or if they're missing some key functionality to avoid errors that I didn't think of. Since the nature of these scripts is similar to that of clamp, I was hoping that a more thorough understanding of exactly what clamp does would help me in designing my own scripts.
Also, if there are already established and/or better names for the ideas behind these scripts, do let me know. These are all just what I came up with off the top of my head; I'm new to maths.
Code:
///clamp(val,min,max)
var val;
if argument[0] < argument[1]
{
val = argument[1];
}
else if argument[0] > argument[2]
{
val = argument[2];
}
else val = argument[0];
return(val);
Why I ask is because I want to create scripts similar to clamp...
Code:
///fold(val,min,max)
var val;
if argument[0] < argument[1]
{
val = argument[2];
}
else if argument[0] > argument[2]
{
val = argument[1];
}
else val = argument[0];
return(val);
Code:
///wrap(val,min,max)
var val;
if argument[0] < argument[1]
{
val = argument[2] - (argument[1] - argument[0]);
}
else if argument[0] > argument[2]
{
val = argument[1] + (argument[0] - argument[2]);
}
else val = argument[0];
return(val);
Code:
///hem(val,min,max)
var val;
if argument[0] < argument[1]
{
val = argument[1] + (argument[1] - argument[0]);
}
else if argument[0] > argument[2]
{
val = argument[2] - (argument[0] - argument[2]);
}
else val = argument[0];
return(val);
These are my interpretations on how to go about the functions I want, but I don't really know if they're the most efficient way to go about things, or if they're missing some key functionality to avoid errors that I didn't think of. Since the nature of these scripts is similar to that of clamp, I was hoping that a more thorough understanding of exactly what clamp does would help me in designing my own scripts.
Also, if there are already established and/or better names for the ideas behind these scripts, do let me know. These are all just what I came up with off the top of my head; I'm new to maths.