I am looking for a function to draw a curve. Could be many functions working together as well.
This is what I am trying to achieve: https://i.stack.imgur.com/rNWgN.png
A curve that goes smoothly between 0 and 1, passing through 2 mid-points defined by 4 variables t1, s and t2, h, or basically x,y coordinates for each points.
I have created this "Curve" using my poor programmatic skills, my non-existent math education and a lot of trial errors: https://www.desmos.com/calculator/bua3q7yuy0
The values I am getting are right, but this is not smooth at all. Here is the same graph with an ideal curve drawn over it (in green): https://i.stack.imgur.com/i6jSJ.png
As you can see, I want some sort of an exponential decay at the beginning/end of my curve, but the "angle" where the decay joins the linear portion of the curve needs to fit as well.
BTW this is what I actually have, translated into code. Not that useful for my question but just to give you more context of how I will be needing it:
float t = 0.2345;
float s = 0.2;
float h = 0.6;
float t1 = 0.1;
float t2 = 0.9;
float t0 = (t - t1) / (t2 - t1);
if (t > t1 && t <= t2) {
value = s + (t0 * (h - s));
}
else if (t <= t1) {
value = (t / t1) * s;
}
else {
const float p = (t - t2) / (1 - t2);
value = h + (p * (1 - h));
}
Any help will be appreciated :) Gab
I recommend a curve (see below) that is obtained as a variation on my superconics, which are described here. For your problem I would use the form
$$ y=(1-(1-x)^p)^q, x\in[0,1] $$
The figure below shows a parametric plot with $p=.25$ and variable $q=[.1,.02,.5]$. I've have highlighted the curve for $q=.26$, which gives a fair approximation to your problem. You can refine the result, of course.
EDIT: I carried through the analysis in Matlab by iterating on $p$ until the difference in $q=\ln(y)/\ln(1-(1-x)^p)$ for the two given points is zero. The result is shown in the figure below.