gnuplot: Cosine oscillating on arbitrary function

To let a cosine oscillate on an "arbitrary" function, when the function goes up the x coordinate might go backwards, so we can't express this as a single-valued function from x to y. But we can use parametric curves, instead; they go from a separate parameter, t, to points (x(t), y(t)). (In gnuplot, this is set parametric.)

As starter, here is what the final result will look like for cosine oscillating on cosine:
gnuplot result of cosine on cosine
This is what motivated myself to write up a blog post about the topic.

gnuplot source code of cosine_on_cosine:

#!/usr/bin/gnuplot -persist

set parametric

f(x) = cos(x*2.*pi)
fDeriv(x) = -sin(x*2.*pi)
g(x) = 0.1*cos(8.*x*2.*pi)
periods=3

set title GPFUN_g.' on '.GPFUN_f

set samples periods*100
plot [0:periods][-0.5:3.5][-2:2] \
    t, f(t) with points, \
    t + cos(atan(fDeriv(t)) + pi/2.)*g(t), f(t) + sin(atan(fDeriv(t)) + pi/2.)*g(t) with points
set samples 100

View raw file

...

[2020-07-27] Sadly, I never got around to write up the full blog post, and now have already forgotten all the details. Let's get this published anyway, now, so I can get on with other things, here...

(Created Thu 09 Apr 2020 02:40:08 CEST, published around Mon 27 Jul 2020 22:40:00 CEST.)