Is there a function formulating bounding values?

64 Views Asked by At

Need to find a mathematical operation formulating such a function:

a<=x<=b,-r<=w<=r,r<b-a
y=x+w, if a<=x+w<=b;
y=b,   if x+w>b;
y=a,   if x+w<a;

enter image description here

This is just similar to mod operation. So is there an operation for the above function?

1

There are 1 best solutions below

0
On

Your function is equivalent to

$$\frac{a + b + |x+\omega - a| - |x+\omega - b|}{2}$$

where $| \cdot |$ denotes absolute value.


You can see an example of this function in action, with $a = 5$ and $b=7$.

I've substituted $y=x+\omega$ in the wolfram alpha demostration to make it easier to see the behavior of the function. As someone has pointed out in the comments, these types of functions are examples of clamping.