Hi,
just wanted to share this function I developed for fun.
Converting to any other language shouldnt be the problem.
Lets take a look at the func itself first:
static const float sqrt2_05=sqrt(2.f)*0.5f;
static const float smi=1e-4;
#define floatn float
floatn circular_sCurve(floatn x,float tau)
{
x-=smi;
float st=sign(sign(-tau)+1);
floatn p2=step(0.5,x);
floatn p3=abs(st-p2);
x=fmod(x*2,1);
x=abs(p3-x);
tau=(1-abs(tau))*sqrt2_05;
tau=min(tau,sqrt2_05-smi);
float tau2=tau*tau;
float remap0=tau-sqrt(1-2*tau2+tau2);
float remap1=1-sqrt(1-tau2);
x=-x*remap0+tau;
floatn X=1-sqrt(1-x*x);
X=(X-remap1)/((1-tau)-remap1);
return (abs(p3-saturate(X))+p2)*0.5;
}
Input values have to be in the range 0..1 for x and -1..1 for tau.
Output lies also between 0 and 1.
Visualized function with different values for tau:
So,why do I call it 'circular'?
Imagine a simple linear function with a rise of 1 which gets 'deformed' by two 'circles' from the left and the right side of the function, respectively.
The amount of 'deformation' depends on tau. For tau=0 you get a linear function. I hope that is understandable.
You can download a small Demo
here where the function is drawn with a dynamic changing tau value.
And eventually the big question:
You: "What the heck is this thing good for?!"
Me: "Well, actually...I´ve no clue^^"
You: "..."
Me: "
"
Have fun!