I suppose this applies to Geometry nodes as well, but the problem came up while I was creating a procedural material. I'm trying to animate a material that mimics the rotating line on a radar. For this material, I need the point slope form of a line, but the points derive from polar coordinates. The problem in this instance is that the equation I need takes the form $$ y = x \frac{sin(\theta)}{cos(\theta)} $$
In the animation, $\theta$ is a function of frame and, of course, $cos(\pi/2)$ is 0, leading to division by 0. This is not a good thing.
Other than trying to arrange drivers to avoid multiples of $\pi/2$, how do I deal with potential domain, Not-A-Number (NAN), or infinity situations in shader math?
EDIT: The solution suggested by John MC in the comments and given in detail by Markus von Broady in his answer does work for this specific case.
But it's not a general solution of NANs. I now suspect that there simply isn't a general solution and one simply has to know the potential domain errors that can come come up and code around them.
EDIT 2: Markus von Broady pointed out that NaN isn't the correct term for the problem I'm trying to solve so I've expanded the phrase to include Domain errors and infinities.
This becomes a bit difficult to follow because Domain errors occur in the mathematics, but NAN and infinites are artifacts of floating point implementations.








