# What equation produces this curve?

I'm working on an engineering project, and I'd like to be able to input an equation into my CAD software, rather than drawing a spline.

The spline is pretty simple - a gentle curve which begins and ends horizontal.

Is there a simple equation for this curve?
Or perhaps two equations, one for each half?
I can also work with parametric equations, if necessary. • Scale as needed: 1+xx(2x-3) – Martijn Courteaux Apr 20 '16 at 9:16
• @MartijnCourteaux I get the normalized cubic $\frac{x(x^2-3)}{2}$ – Jaume Oliver Lafont Apr 20 '16 at 13:23
• I'm a civil engineer and this looks like the design of a prestressed cable (I appologize if I'm wrong). If so, then such cables are usually designed with quadratic equations (or straight lines), in which case you'd want to use one parabola for each half or use quadratic Beziers which work in much the same way as the cubics described in MarkH's answer. – Wasabi Apr 20 '16 at 19:08

## 11 Answers

These splines are usually drawn as Bézier curves. Specifically, since it is defined by four points, the curve is a cubic Bézier. $$\vec{x} = (1-t)^3\vec{P_0} + 3(1-t)^2t\vec{P_1} + 3(1-t)t^2\vec{P_2} + t^3\vec{P_3}$$ with \begin{align} \vec{P_0} &= (-60, 20),\\ \vec{P_1} &= (0, 20),\\ \vec{P_2} &= (0, -20),\\ \textrm{and}\ \vec{P_3} &= (60, -20). \end{align} The variable $t$ is $0$ at the left end of the curve and $1$ at the right end. With these points, the origin is in the center of the figure. Taking $x$- and $y$-coordinates separately, we have \begin{align} x(t) &= -60(1-t)^3 + 60t^3\\ y(t) &= 20(1-t)^3 + 60(1-t)^2t - 60(1-t)t^2 - 20t^3. \end{align} After some arithmetic, these simplify to \begin{align} x(t) &= 60(2t^3 - 3t^2 + 3t - 1)\\ y(t) &= 20(4t^3 - 6t^2 + 1). \end{align}

I've overlapped the curves below to show that they match. The green is the original curve from your picture; the blue is the curve from the equations above. • @Giffyguy: Or, if you rather replicate my curve for $(0,40)$ to $(120,0)$, use control points $(0,40), (40,40), (80,0), (120,40)$; or, $(-60,20), (-20,20),(20,-20), (60,-20)$ if center is at origin. That would be the Bézier variant with $x$ linear, you see. Moving the center control points along the $x$ axis, antisymmetrically, will modify the steepness of the curve in the center. – Nominal Animal Apr 20 '16 at 4:37
• My guess would have been that the nodes we see in the picture are the control points ... So $(-60,20), (0,20), (0,-20), (60,-20)$? – Hagen von Eitzen Apr 20 '16 at 8:21
• pomax.github.io/bezierinfo – BlackBear Apr 20 '16 at 9:57

You could try a sine or cosine wave. Taking the lower left corner as the origin, let $$y=20\cos\left(\frac {\pi x}{120}\right)+20$$

This can also be written as $$y=40\cos^2\left(\frac{\pi x}{240}\right)$$

• A neat solution too. Not very far from the cubic equation as represented here. – Raymond Manzoni Apr 19 '16 at 22:27
• This isn't the exact answer to my question (the way it's worded), but it's the solution I ended up using, since it produces a maximally smooth curve - smoother than the cubic Bézier was. Thanks for the help! – Giffyguy Apr 20 '16 at 22:39
• You're welcome. Pleased to be of help. – David Quinn Apr 20 '16 at 22:45
• @Giffyguy You might want to consider that using a trigonometric function often is way slower than some basic arithmetic operations. So if you have to call this often, using Mark H's answer can improve speed. – Alfe Apr 21 '16 at 9:57
• @Giffyguy I'm curious about what you mean by "maximally smooth." What's your definition/criteria? – Mark H Apr 21 '16 at 10:36

Most of the other responses will, outside the given range, be either: (a) cyclical (come back up & down repeatedly), or (b) diverge to +/- infinity at the limit (far away from the origin). If it's at all important that the tails have horizontal asymptotes in the limit, then you want some flavor of logistic function:

$$f(x)= \frac{L}{1+e^{-k(x-x_0)}}$$ • Note, though, that this function doesn't go to a "nice" value at any particular value of $x$; for example, if I want $f(-4) = 0$ and $f(4) = 1$, you'll have to offset the function by an additive constant, and the values of $L$ will be some complicated expression in terms of exponentials. This is really the flip-side of the problem you point out: this function automatically has nice behavior outside the interval, but is uglier if you want precise control at the boundaries of the interval. – Michael Seifert Apr 20 '16 at 17:01
• This is also referred to (often in computer science) as a sigmoid curve en.wikipedia.org/wiki/Sigmoid_function – mike Apr 21 '16 at 13:43

Assuming you mean \begin{align} y(0) &= 40 \\ y(120) &= 0 \\ \dot{y}(0) &= 0 \\ \dot{y}(120) &= 0 \end{align} then a simple cubic will do: $$y(x) = \frac{x^3}{21600} - \frac{x^2}{120} + 40$$

At range $$x=0\dots120$$, it looks like this: You can find these very easily. In general, a cubic curve is $$y(x) = C_3 x^3 + C_2 x^2 + C_1 x + C_0$$ and its derivative $$\dot{y} = \frac{d y(x)}{d x} = 3 C_3 x^2 + 2 C_2 x + C_1$$ Fix four values, each fixing one of the constants, and that's it.

• I obtained $\boxed{ \displaystyle P(x) = \frac{x^3}{21600} - \frac{x}{2}}$ with the same method (with the derivative proportional to $x^2-60^2$). – Raymond Manzoni Apr 19 '16 at 21:51
• @RaymondManzoni I think that is even negative in parts the function in the question is positive...If at all, I thinkl it should be $\;-x^3\;$ and some coefficients here and there. – DonAntonio Apr 19 '16 at 21:53
• my solution is centered at $0$ it may of course be shifted up by adding $20$ and/or translated by replacing $x$ with $x-x_0$... – Raymond Manzoni Apr 19 '16 at 21:54
• @Joanpemo It's fine if they go negative, I can easily transform to place the origin wherever I need it. Apart from that, I'm still tinkering with the information to see how it operates. Do you see any major problems? – Giffyguy Apr 19 '16 at 21:55
• @Joanpemo What do you mean by "twisted brother"? It seems like a normal cubic to me: what's wrong with it? – Fund Monica's Lawsuit Apr 20 '16 at 3:39

I assume origin is at middle of vertical y-axis line. Mathematica code and plot:

Plot [ 20 Cos[ Pi x/120], {x, 0, 120}, AspectRatio -> 1/3, GridLines
-> Automatic, PlotStyle -> Thick]


$$y = 20 \cos \frac{\pi x}{120} ,\, (0 EDIT1:

Or a cubic whose domain/range box dimension can be varied:

$$\dfrac{y}{x}= \dfrac{3b}{2a}\big(\dfrac{x^2}{3 a^2}-1\big)$$ a = 60; b = 20;
Plot[3 b/(2 a ) \,x \;( x^2/(3 a^2) - 1) , {x, -a, a}, PlotStyle -> {Thick, Blue}, AspectRatio -> 0.2, GridLines -> Automatic, AxesLabel -> {X, Y}, GridLinesStyle -> Directive[Gray]]

• This isn't the exact answer to my question (the way it's worded), but it's the solution I ended up using, since it produces a maximally smooth curve - smoother than the cubic Bézier was. Thanks for the help! – Giffyguy Apr 20 '16 at 22:40
• Ok but wonder what exactly is needed for an acceptable answer. We can for example set it so that the central max slope is manipulable as a variable using boundary values in odes, right from saw tooth to diagonal line. – Narasimham Apr 20 '16 at 22:54
• This answer is fabulous, and I'm using it as my final solution. It just so happens that the explicit wording of my question technically asks for the cubic Bézier (even though I didn't realize that was its name at the time). That's the reason I accepted Mark H's answer. – Giffyguy Apr 20 '16 at 22:58

Using elementary functions, one that roughly approximates your diagram is $f(x)=-\frac{40}{\pi}\arctan(\frac{x}{10})+20$. It isn't a great fit, but a rough approximate.

Using non-elementary functions, your plot looks really similar to a mirrored normal distribution cumulative curve, which is based on the error function and defined as $\mathbb{erf}(x)=\frac{2}{\sqrt{\pi}}\int_0^x e^{-t^2}dt$. Your diagram could be modeled with this, and it looks like it would fit more closely than the elementary function attempt: $f(x)=-20\mathbb{erf}(\frac{x}{30})+20$.

These models are based off of $f(0)=20$, although they easily could be shifted to fit whatever value you would like for $f(0)$.

With two equations, a parabola can be used for each half.

Imposing the three conditions $$f(0)=0,$$ $$f(60)=-f(-60)=-20,$$ and $$f'(60)=f'(-60)=0$$

results in the expression $$f(x)=\frac{x^2 sgn(x)}{180}-\frac{2x}{3},$$

where $sgn(x)$ is the sign function.

The slope is $-\frac{2}{3}$ at the origin (see the graphic here).

It does look a bit like $-\tan^{-1}x$ if you were searching a similar looking curve. I think that modifying the equation a bit : like multiplying it by some constant k and taking the curve from $[-x,x]$ and x does not tend to $\infty$ would result into the part of the curve you have shown

I think you can figure out the rest for yourself. Good Luck!

I am an professional electrical engineer (according to the gubbermint of California), so I will give you an engineer's answer that is sure to be offensive to the math people here.

Download a program called "Curve Expert" Just get the basic program, not the professional version. Input your data, and you will get a better fit than you want. From your graph, it could be a sinusoid, a polynomial, an inverse hyperbolic sine, a rational function, something built from the cumulative normal distribution, or some kind of logistic function.

Curve expert will help you decide what is best. You will probably fall in love with it and buy the license when the trial period expires.

*** disclaimer: I have used curve expert for years, but have no financial, romantic, political, or other interest in it.

There are many alternatives, and you didn't give us enough information to choose between them intelligently. So, here are a few options; you can choose.

I assume that the coordinate system origin is at the center of the curve.

(1) Parametric Cubic in Bézier Form
This is the obvious choice because the symbols on your picture look like the control points of a cubic Bézier curve. These control points are $\mathbf{P}_0 = (-60,20)$, $\mathbf{P}_1 = (0,20)$, $\mathbf{P}_2 = (0,-20)$, and $\mathbf{P}_3 = (60,-20)$. Then the curve is $$\mathbf{P}(t) = (1-t)^3 \mathbf{P}_0 + 3t(1-t)^2 \mathbf{P}_1 + 3t^2(1-t) \mathbf{P}_2 + t^3 \mathbf{P}_3$$ In fact, more generally, you can take $\mathbf{P}_1 = (-k,20)$, $\mathbf{P}_2 = (k,-20)$, and you'll still get a curve of roughly the desired shape. You can adjust $k$ to get exactly the shape you want.

(2) Real-Valued Cubic in Algebraic Form
If you're going to use the curve as a "law" to control variation of some variable, then you want it to be in the form of a real-valued function $y=f(x)$. The parametric equation given above is inconvenient because, given a value of $x$, it's not easy to find the corresponding value of $y$. A suitable equation is: $$y = px(x^2 - q)$$ Using the relations $y(60) = -20$ and $y'(60)=0$, you can calculate $p$ and $q$.

(3) Real-Valued Cubic in Bézier Form
Another option is to write the equation in Bézier form, again. If we let $u = \tfrac{1}{120}(x+60)$, then $u= 0$ when $x=-60$ and $u=1$ when $x=60$. The equation of the curve is $$y = a(1-u)^3 + 3au(1-u)^2 - 3au^2(1-u) - au^3$$ where $a=20$. In a CAD system, you can construct this curve by using the control points $\mathbf{P}_0 = (-60,20)$, $\mathbf{P}_1 = (-20,20)$, $\mathbf{P}_2 = (20,-20)$, and $\mathbf{P}_3 = (60,-20)$. So, this is the case $k=20$ of #1 above.

(4) Real-Valued Quintic in Bézier Form
One problem with the real-valued cubics is that they give you no freedom to adjust the shape of the curve. To get some adjustment freedom, you can use a quintic curve, instead. Again, it's easiest to write this in Bézier form. So, as before, we let $u = \tfrac{1}{120}(x+60)$. Then the equation of a suitable quintic is $$y = a(1-u)^5 + 5au(1-u)^4 + 10bu^2(1-u)^3 - 10bu^3(1-u)^2 - 5au^4(1-u) - au^5$$ where $a=20$, again. You can change the value of $b$ to adjust the shape of the curve. In your CAD system, you can construct this curve using the control points $\mathbf{P}_0 = (-60,20)$, $\mathbf{P}_1 = (-36,20)$, $\mathbf{P}_2 = (-12,b)$, $\mathbf{P}_3 = (12,-b)$, $\mathbf{P}_4 = (36,-20)$, and $\mathbf{P}_5 = (60,-20)$. The particular choice $b=20$ gives you a curve whose second derivatives are zero at the start and end, which may have some merit in your application. Here are curves with $b = 0,5,10,15,20$. (5) Quadratic B-spline
Using four control points (like the ones described in #1 or #3), you can define a b-spline curve of degree 2 (i.e. quadratic) that has two segments. Each quadratic segment will actually be a parabola, so the solution is then two parabolas joined end-to-end with tangent continuity. There will be a discontinuity of curvature at the inflexion point where the two pieces meet, and this might be a problem in an aerodynamics application. None of the other solutions I listed have this problem.

(6) Trigonometric Solutions
Several people gave solutions using trigonometric functions. I don't recommend these. CAD systems usually support only polynomial and rational curves (Bézier curves and NURBS curves). They don't support curves described by trigonometric functions. So, if you use trig functions, you will have to approximate, and you'll end up with a spline curve with many segments and wiggly curvature, which will be bad for aerodynamics. All the curves I suggested above can be exactly represented in a typical CAD system, so they don't have this problem.

• Thanks for detailing each of these. I just have to say for #5, I've only ever used one particular CAD system, AutoDesk Inventor, which does support trig curves with none of the problems you mentioned. However, this may not be the case for other CAD systems, so that info might be good for other people reading over this. However, I'm currently comparing parabolas to the trig solutions, and I'll probably switch to parabolas anyway, since they are more certainly what I am looking for - with the bonus of being polynomial/rational functions, as opposed to the trig solutions. – Giffyguy Apr 22 '16 at 15:20
• I'm surprised Inventor supports trig curves. They're not supported by data exchange standards like IGES or STEP. Are you sure they don't get approximated by splines? Two parabolas joined end-to-end would work. In fact, this would be a b-spline of degree 2 with 2 segments. You can define this curve using the same control points as in #1. – bubba Apr 23 '16 at 0:20

Note: Now that I've finished this derivation, I see it's the same as Jaume Oliver Lafont's answer. Perhaps some extra justifications will be useful.

In looking over @Giffyguy's comments on other answers, it seems the real goal is to have a curve with minimum curvature or maximum smoothness. I'll take this to mean the maximum absolute value of the second derivative should be minimized. The way to minimize the second derivative everywhere is to make it everywhere constant, which means we're dealing with a parabola $$y(x) = ax^2 + bx + c$$ with constraints $$y(0) = 0$$ $$y(60) = -20$$ for the right half, and $$y'(60) = 0.$$

The first constraint means $c = 0$. The second and third constraints result in, respectively, $$a(60)^2 + b(60) = -20.$$ $$2a(60) + b = 0$$ Solving results in $a = \frac{1}{180}$ and $b = \frac{2}{3}$. So, $$y = \frac{1}{180}x^2 - \frac{2}{3}x = \frac{x(x-120)}{180}$$

The second derivative has a constant value of $1/90$, which is smaller than the maximum value of the second derivative of the cosine functions ($1/60$) and the cubic polynomial ($\approx 1/72$). The function spanning the full width would be $$y(x) = \left\{ \begin{array}[ll] \\ -\frac{x(x+120)}{180} & x \lt 0 \\ \frac{x(x-120)}{180} & x \geq 0 \\ \end{array} \right.$$

• Thanks for going the extra mile. This is kind of an XY problem, it seems, and my question was very brief. I'll leave your Bézier answer as the accepted answer, since the question is worded the way it is. – Giffyguy Apr 22 '16 at 16:31
• After several hours dealing with support forums for my CAD software, it was determined that my CAD software does not support the Sign function (or the Abs function, oddly enough). So I'm doubly grateful that you also split the equations out into two halves, one for each sign. It's a little obnoxious that I have to plot two curves, simply because it will interfere with the flexibility of the drawing down the road, but I've got nobody to blame except the CAD developers. :) – Giffyguy Apr 22 '16 at 18:59
• @Giffyguy If the problem with the sign function from this list is that it is defined as 0 for negative and 1 for positive, the standard sign between -1 and 1 is $2sign(x)-1$. – Jaume Oliver Lafont Apr 24 '16 at 23:19