# Thread: Need to control a curve..

1. ## Need to control a curve..

I'm afraid I'm a bit of a math cosumer more than a mathametician & I would be very indepted if someone could show me a formula.

I'm working on a computer-graphics application and I need to fade a value non-linearaly over the range of 0 to 1. Where Y = 0 at 0, and Y = 0 at 1, and Y = 1 somewhere in between. Beyond X= 0 and X= 1 it will be clipped, so I don't care what Y is beyond those values.

The graph in this image is Y = sin(x^K * 3.14156) which has the basic shape I'm after, but would like more control over the slopes on the left and right of the peak, and the placement of the peak. (despite the values on the X axis, the interval of X is 0 - 1.
All the best,
Byron

2. Hi

The derivative of $Y = \sin(\pi\:x^k)$ is $Y = k\:\pi\:x^{k-1}\:\cos(\pi\:x^k)$

The derivative is equal to 0 for $x=0$ and $\pi\:x^k = \frac{\pi}{2}$

If you need to control the peak, for instance have the peak at a given value $x_0$ then you have to chose k such that $\pi\:x_0^k = \frac{\pi}{2} \Rightarrow x_0^k = \frac{1}{2} \Rightarrow k\:\ln(x_0) = -\ln(2) \Rightarrow k = -\frac{\ln(2)}{\ln(x_0)}$

3. I can help a little

The placement of the peak is detrmined by k in fact the peak occurs

at 1/[2^(1/k]

So to put the peak at say x= a solve 1/[2^(1/k] = a

this yields k = -ln(2)/ln(a)

I guess I'm a little slow here

4. ## Need to control a curve

Many thanks! makes perfect sense once I look at it. The curve will start at 0 and peak when x^K*pi = radians(90) won't it, so I'd just adjust K to determine at what value of X I hit .5 pi.

Is there anything (simple) you can see that can modify the slopes on either side or will I have to investigate bezier curves & the like?

( this is going into a real time shader in a video game, so it needs to be relatively computationaly inexpensive )

Many thanks again,
Byron

5. Can you be more precise about the slopes you want to control ?
On the left side of the peak there is obviously an inflection point. The slope at this point is the maximum.
On the right side the slope seems to be maximum (absolute value) at the end.

6. ## Need to control a curve..

Yes, if you look at the picture here I'd ideally want near-independent control of the peak and the deflection of the curve from each of the black lines on the up & down side (e.g., be able to move the red curve up to be the orange etc..)

Best
Byron

7. If I have well understood you would like to have the peak at the same place (not moving) and move the the red curve up to the orange one.

This is not feasible with a simple function like $Y = \sin(\pi\:x^k)$ because as we saw before the position of the peak determines the value of k and therefore Y function.

There should be something more like $Y = f(x)\: \sin(\pi\:x^k)$

8. Originally Posted by running-gag
If I have well understood you would like to have the peak at the same place (not moving) and move the the red curve up to the orange one.

This is not feasible with a simple function like $Y = \sin(\pi\:x^k)$ because as we saw before the position of the peak determines the value of k and therefore Y function.

There should be something more like $Y = f(x)\: \sin(\pi\:x^k)$
Right, I'm hoping there exists some relatively computationally inexpensive function with three free parameters to control A: the peak, B: the inflection left of peak and C: inflection right of peak.