1
$\begingroup$

UPDATE: I feel like my original question was too vague and didn't provide enough information (as others have mentioned). So I'm going to restate it.

Purpose: I want to find an equation in order to provide a smooth slope for an animation that I am creating. My animation consists of a lever and a set of numbers on a horizontal line. As you move the lever up and down the numbers will slide down and up the line (opposite of the lever). I want to create a smooth curve so that the user can "feel" the speed increasing the further they get away from the center. Most of the time, the user will stay within the main part of the screen, therefore I want the sliding numbers to go slowly for that space. But once they get closer to the top or bottom I want the increase in speed to be relatively quick.

Requirements: The variables are the distance from center that the lever is, $x$, and the distance that the numbers should move, $y$. I need $x=y=0$ so there is no movement at the center. $y$ should be positive when $x$ is positive, but $y$ can be positive or negative when $x$ is negative. The graph just needs to be symmetric for $x=0$ or $x=y$.

Right now I'm using a simple parabola $y = (0.03*x)^2$ but I would like the middle space to be "stretched out." Therefore, is there a function that I can use that would have some constants (maybe some points) to define what kind of slope is found for, lets say $x=0$ to $x=100$ and then it curving to another point at $x=160$.

I don't want to use piecewise because unless I use a lot of pieces, the user will be able to "feel" the positions where the equation changes. I think Quadratic Bézier curve might do the trick, but if it can, I would need help in understanding how to use it.

Question: is the Quadratic Bézier curve what I should be looking into, if not, what do you suggest? If it is, do you have a suggestion of what equation I should use or at least a reference were I can relearn it.


Old question: I need to come up with an equation for a curve but I have forgotten most of my calculus by this point. What I need very close to a parabola that opens up. I'm currently using y = (0.03*x)^2 but this does not have a fast enough slope on the ends.

I need the slope in the middle to be very gradual, and then near the ends to increase faster.

I'm guessing this won't be a standard parabola, but I'm not just sure what I should be looking for.

UPDATE: Attempting to be more detailed with my "requirements." This is for a computer animation and a user is sliding a "lever" up and down. As they do so a set of numbers are scrolling the opposite direction on the side. The further away the lever is from center, the faster the numbers should go. Thus, I want the edges (top and bottom) to make the numbers go much faster. But for most of the main section of the screen, they shouldn't go so fast. But I want the transition from slow to fast to be noticeable so that it feels intuitive to the user.

Thus, I need a function that has a high value for y as x gets larger, but I want the edges to have a greater slope. Bézier curve looks like it might work? But it has been a long time since I've used it. Anyone have suggestions for how to use it in this context?

  • 0
    A quadratic Bézier curve *is* a parabola.2016-12-12

1 Answers 1

2

I think the easiest way may be piecewise—not piecewise-linear, but a piecewise-defined function that is relatively smooth, so there isn't a point where the speed suddenly changes. Let's say that you want slope $m$ for $-a\le x\le a$ (and $y=0$ when $x=0$), then curving up to the point $(b,c)$. $y=\begin{cases} \frac{-a^2 c+a^2 b m}{(a-b)^2}-\frac{\left(2 a c-a^2 m-b^2 m\right) x}{(a-b)^2}+\frac{(-c+b m) x^2}{(a-b)^2} & \text{ if } x<-a \\\\ mx & \text{ if } -a\le x\le a \\\\ -\frac{-a^2 c+a^2 b m}{(a-b)^2}-\frac{\left(2 a c-a^2 m-b^2 m\right) x}{(a-b)^2}-\frac{(-c+b m) x^2}{(a-b)^2} & \text{ if } x>a \end{cases}$ (I arrived at this formula by having Mathematica solve for the coefficients of the quadratic polynomial that would go through the point at the end of the linear segment and the other given point and have the same slope as the linear segment at the splice point: a1 x^2 + a2 x + a3 /. Solve[a1 a^2 + a2 a + a3 == a m && 2 a1 a + a2 == m && a1 b^2 + a2 b + a3 == c, {a1, a2, a3}].)

For example, if you wanted a slope of $\frac{1}{4}$ from -100 to 100, then curving up to (180,150), $a=100$, $m=\frac{1}{4}$, $b=180$, $c=150$, and $y=\begin{cases} -\frac{2625}{16}-\frac{97 x}{32}-\frac{21 x^2}{1280} & \text{ if } x<-100 \\\\ \frac{1}{4}x & \text{ if } -100\le x\le 100 \\\\ \frac{2625}{16}-\frac{97 x}{32}+\frac{21 x^2}{1280} & \text{ if } x>100 \end{cases}$

graph of example


edit: even smoother would be to use a cubic polynomial for the end parts and force it to match the first and second derivatives at the splice points (a1 x^3 + a2 x^2 + a3 x + a4 /. Solve[a1 a^3 + a2 a^2 + a3 a + a4 == a m && 3 a1 a^2 + 2 a2 a + a3 == m && 6 a1 a + 2 a2 == 0 && a1 b^3 + a2 b^2 + a3 b + a4 == c, {a1, a2, a3, a4}]):

$\begin{cases} \frac{-a^3 c+a^3 b m}{(a-b)^3}-\frac{\left(3 a^2 c-a^3 m-3 a b^2 m+b^3 m\right) x}{(a-b)^3}+\frac{3 a (-c+b m) x^2}{(a-b)^3}-\frac{(c-b m) x^3}{(a-b)^3} & x<-a \\\\ m x & -a\leq x\leq a \\\\ -\frac{-a^3 c+a^3 b m}{(a-b)^3}-\frac{\left(3 a^2 c-a^3 m-3 a b^2 m+b^3 m\right) x}{(a-b)^3}-\frac{3 a (-c+b m) x^2}{(a-b)^3}-\frac{(c-b m) x^3}{(a-b)^3} & x>a \end{cases}$

For example, if you wanted a slope of $\frac{1}{4}$ from -100 to 100, then curving up to (180,150), as above, $a=100$, $m=\frac{1}{4}$, $b=180$, $c=150$, and

$y=\begin{cases} \frac{13125}{64}+\frac{1639 x}{256}+\frac{63 x^2}{1024}+\frac{21 x^3}{102400} & x<-100 \\\\ \frac{x}{4} & -100\leq x\leq 100 \\\\ -\frac{13125}{64}+\frac{1639 x}{256}-\frac{63 x^2}{1024}+\frac{21 x^3}{102400} & x>100 \end{cases}$.

graph of example


original answer: Would $y=\cot(3x+0.07)$ for $0\le x\le 1$ work? Or $y=-\frac{x-0.5}{(x+0.1)(x-1.1)}$?

  • 0
    @$R$yanJM: For the quadratic, for example, I started with a generic quadratic, a1*x^2+a2*x+a3, and used that with the conditions to write 3 equations, then solved for a1, a2, and a3. (For the cubic, same idea, but 4 coefficients and 4 equations.) As J.M. said, there's a Mathematica command, `InterpolatingPolynomial[]` that ta$k$es the conditions and returns a $p$oly$n$omial without having to do the intermediate setup and solving.2010-11-04