# How to calculate a smooth tangent wave that has no periodic delays

graphing-functionstangent line

I want to use a tangent function to create a waveform that always passes itself back to -1 at the end of each cycle to 1.

When a tangent function only moves between -1 and 1, there is a gap left between each tangent path on the x axis.

I perfectly filled the area by simply using a second tangent of n + pi/2 which filled the region, to create the repeating tangent I wanted.

I then tried to combine the formulas using the minimum function, but it seems to cut the graph in half, all values above 0 are just missing, which is not what I want.

How can I get a repeating tangent between y -1 and 1 that never has x axis gaps?

(I drew the y > 1 and y < -1 to represent my use case, where any value below -1 and above 1 are useless)

Graph on desmos here

My end goal is to create a formula that can essentially do this:

Consider one branch of the tangent function. You're restricting the range of $$\tan(x)$$ to $$[-1,1]$$, which means $$x\in\left[-\frac\pi4,\frac\pi4\right]$$.

Since $$\tan(x) = \tan(x\pm n\pi)$$ for integer $$n$$, restricting the range to $$[-1,1]$$ for the entire plot of $$\tan(x)$$ would make for a domain of $$\cdots\cup\left[-\frac{5\pi}4,-\frac{3\pi}4\right]\cup\left[-\frac\pi4,\frac\pi4\right]\cup\left[\frac{3\pi}4,\frac{5\pi}4\right]\cdots$$. We can write this compactly by observing

$$x\in\left[-\frac{5\pi}4,-\frac{3\pi}4\right] \implies -\frac\pi4 \le x+\pi \le\frac\pi4 \implies |x+\pi| \le\frac\pi4$$

$$x \in \left[-\frac\pi4, \frac\pi4\right] \implies -\frac\pi4 \le x \le \frac\pi4 \implies |x| \le \frac\pi4$$

$$x\in\left[\frac{3\pi}4,\frac{5\pi}4\right] \implies -\frac\pi4 \le x-\pi \le\frac\pi4 \implies |x-\pi| \le\frac\pi4$$

and so on, such that the restricted domain is $$|x+n\pi|\le\frac\pi4$$, where $$n$$ is an integer.

We can fill in the gaps by shifting $$\tan(x)$$ by $$\frac\pi2$$, as the other answer suggests. Then we could define this function piecewise as

$$\operatorname{smoothtan}(x) = \begin{cases} \tan(x) & \text{if } |x+n\pi|\le\frac\pi4 \quad (n\in\mathbb Z) \\ \tan\left(x\pm\frac\pi2\right) & \text{otherwise}\end{cases}$$

(though "smooth" is not the best name for this function)