Function Repository Resource:

SmoothStep

Source Notebook

A sigmoidal interpolation function

Contributed by: Flip Phillips (FlipPhillips.com)

ResourceFunction["SmoothStep"][x]

returns a sigmoidal, Hermite interpolation between [0,1] for x on [0,1].

ResourceFunction["SmoothStep"][x,{min,max}]

returns a sigmoidal, Hermite interpolation between [0,1] for x on [min,max].

Details and Options

ResourceFunction["SmoothStep"] is an interpolation function commonly used in computer graphics.
The ResourceFunction["SmoothStep"] implementation is consistent with the GL and RenderMan (RSL) shading languages.
ResourceFunction["SmoothStep"][x] clamps to 0 or 1 for x less than or greater than 0 or 1, respectively.
ResourceFunction["SmoothStep"][x,{min,max}] is the same as the RenderMan smoothstep(min,max,x) invocation.
ResourceFunction["SmoothStep"] is not second-order continuous at either x=0 or x=1. This creates discontinuities. The resource function SmootherStep solves this problem.

Examples

Basic Examples (2) 

The function is sigmoidal and inputs smaller than 0.5 underestimate the input:

In[1]:=
ResourceFunction["SmoothStep"][0.1]
Out[1]=

Values larger than 0.5 do the opposite:

In[2]:=
ResourceFunction["SmoothStep"][0.7]
Out[2]=

Plot the function:

In[3]:=
Plot[ResourceFunction["SmoothStep"][x], {x, -1, 2}]
Out[3]=

Scope (2) 

The single-argument form of SmoothStep passes through the point {0.5,0.5}:

In[4]:=
ResourceFunction["SmoothStep"][0.5]
Out[4]=

Specify an input domain by giving a second argument:

In[5]:=
Plot[ResourceFunction["SmoothStep"][x, {-1, 1}], {x, -2, 2}]
Out[5]=

Applications (2) 

Smoothly interpolate with more gradual changes at the start and stop of the interpolation domain:

In[6]:=
Plot[{x, ResourceFunction["SmoothStep"][x]}, {x, 0, 1}]
Out[6]=

Interpolate colors:

In[7]:=
Table[Hue[x], {x, 0, 1, .1}]
Out[7]=
In[8]:=
Table[Hue[ResourceFunction["SmoothStep"][x]], {x, 0, 1, .1}]
Out[8]=

Properties and Relations (1) 

The derivative of SmoothStep approaches 0 as x approaches 0 or 1 from either side:

In[9]:=
Limit[D[ResourceFunction["SmoothStep"][x], x], x -> 0]
Out[9]=
In[10]:=
Limit[D[ResourceFunction["SmoothStep"][x], x], x -> 1]
Out[10]=

Possible Issues (1) 

SmoothStep is second-order discontinuous at x=0 and x=1:

In[11]:=
Plot[ResourceFunction["SmoothStep"]''[x], {x, -1, 2}]
Out[11]=

Neat Examples (1) 

SmoothStep approximates the animation technique of "ease-in / ease-out":

In[12]:=
Animate[Graphics[
  Text["Zoom!", {ResourceFunction["SmoothStep"][x], 0}], PlotRange -> {{-.1, 1.1}, {-.1, .1}}], {x, -1, 2}]
Out[12]=

Publisher

Flip Phillips

Version History

  • 1.0.0 – 08 August 2019

Source Metadata

Related Resources

License Information