Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I'm trying to create a slider that lets the user pick a value as low as some given minimum, or as high as some given maximum. The slider must also, when positioned half way, have a value that is some given "mid point".

So I'm looking for an increasing function $f(x) : [0,1] \to \mathbb{R}$ such that

$f(0)=k_{\mathrm{min}}$

$f(\frac{1}{2})=k_{\mathrm{mid}}$

$f(1)=k_{\mathrm{max}}$

for any $k_{\mathrm{max}} ≥ k_{\mathrm{mid}} ≥ k_{\mathrm{min}}$.

What could I choose? My first thought was a quadratic, since I have three unknowns, but this was non-inreasing for some values.

Thanks.

share|improve this question
1  
I think a quadratic should work as long as the middle point is actually in between the min and the max... How did you get non-increasing functions? –  Vhailor Aug 23 '11 at 15:53
    
Is piecewise linear too simple? –  Hans Lundmark Aug 23 '11 at 16:12
    
@Vhailor: consider the function $f(x) = -(x-1)(x-3/4)+3/4$. $f(0) = 0$, $f(1) = 3/4$, $f(1/2) = 3/4 - 1/8$. $f$ attains a global maximum at $x = 7/8$. –  Willie Wong Aug 23 '11 at 17:15
add comment

1 Answer

up vote 0 down vote accepted

There are many ways of fitting a function to your requirements. Here is one particular way, which assumes some sort of power law type distribution between the min and the max values.

We first define the case where the min is 0 and the max is 1. Then we can set

$$ f(x; k_{\mathrm{min}}, k_{\mathrm{max}}, k_{\mathrm{mid}}) = k_{\mathrm{min}} + (k_{\mathrm{max}} - k_{\mathrm{min}})\cdot f(x; 0,1, k) $$

where

$$ k = (k_{\mathrm{mid}} - k_{\mathrm{min}}) / (k_{\mathrm{max}} - k_{\mathrm{min}}) $$

Now we consider the function $g(x) = x^p$. This function satisfies $g(0) = 0$, $g(1) = 1$, and it is guaranteed to be increasing between 0 and 1. It suffices to find the $p$ such that $g(1/2) = k$. We solve:

$$ (1/2)^p = k \iff p = - \log_2 k $$

So in the end we can take the function

$$ f(x; k_{\mathrm{min}}, k_{\mathrm{max}}, k_{\mathrm{mid}}) = k_{\mathrm{min}} + (k_{\mathrm{max}} - k_{\mathrm{min}}) x^{\log_2 (k_{\mathrm{max}} - k_{\mathrm{min}}) - \log_2 (k_{\mathrm{mid}} - k_{\mathrm{min}})} $$

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.