6

Three years of calculus in college have served me nothing, apparently, since I can't for the life of me remember even the basics. I'm working on a small software project where I have a table with say 20 cells, and I want the cells' opacity to go down as the index goes up.

Currently, I'm doing it linearly with $\textrm{opacity} = 1 - (\textrm{index}/20)$, or $y = 1-x$. The curve I'm going for is something where at the beginning I have a high value for the opacity, 1, but then it starts dropping like a roller-coaster, non-linearly. The best I can describe it is it looks like half of a 'C' draw on the positive xy axis.

The closest I got was $y = e^x$, but that plot goes up. Can anyone tell me the name of what I'm looking for?

Edit: Ok it turns out what I'm looking for is a hyperbola, $y = 1/x$. However, since this is a opacity value, the range needs to be from $0$ to $1$, while the domain is also $0$ to $1$. But I'm getting some large values for small inputs.

Snowman
  • 2,664

3 Answers3

6

Since your domain and range are both $[0,1]$, you can try the curve $$\sqrt{x} + \sqrt{y} = 1$$ i.e. $$y = (1-\sqrt{x})^2$$ enter image description here

3

Experimenting with largish coefficients for the $x$ term, e.g.

$y = \dfrac{1}{36x}$:

enter image description here


You might also want to experiment with graphs of the following equation: for any $a < 1$ (the lower the value of $a$, the greater the curve):

$$x^a+y^a=1 \iff y=(1-x^a)^{1/a}, \quad 0 < a < 1$$

E.g. Letting $a = \large \frac35$, below is the graph of $\displaystyle y = (1 - x^{\large \frac35})^{\large \frac53}$:

enter image description here

And letting $a = \large \frac{7}{12}$, below is the graph of $\displaystyle y = (1 - x^{\large\frac{7}{12}})^{\large\frac{12}{7}}$

enter image description here

amWhy
  • 209,954
  • Yes those are the ones I'm looking for, but the problem is, given an x value from 0 to 1, how do I map respective y values in the range of 0 to 1 as well? – Snowman Dec 23 '12 at 01:07
  • Try $y = (1-x)^2$ or $y = (1-x)^\alpha$ with $\alpha > 1$, until it looks right. – Hans Engler Dec 23 '12 at 01:10
3

As an extension to Marvis' answer, any function of the form

$$x^p+y^p=1\implies y=(1-x^p)^{1/p}$$

where $0<p<1$ will work, with more curvature the lower $p$ is. Another alternative is to use a circular arc:

$$(x-1)^2+(y-1)^2=1\implies y=1+\sqrt{1-(x-1)^2}$$

If you don't need it to be vertical at $x=0$, polynomials like $y=(x-1)^{2n}, n=1,2,3...$ might work. You get a steeper drop with larger $n$. If efficiency is an issue and you don't need to match a plot exactly, this is probably less expensive, thought it might not "curve as evenly" as you'd like it to.