I've seen discussions about this but with too many details left out. I have an ellipse with the standard parameters: $h, k, a, b$ and a rotation angle. (I can convert all that to the general form coefficients: $A, B, C, D, E,$ and $F$ if needed)
To get the tangent line, I check to see if the slope equals infinity or not and do some very simple math (no trig) to generate a couple of points, thus defining a line.
But getting the slope is proving to be problematic. I check to see if either the x or y of the given point are at any extrema (pre-calculated) and set the slope to $0$ or infinity, accordingly. But I can't seem to work out the math for the "normal" cases.
I can use $$-(\frac{x}{ y} \cdot \frac{b^2}{a^2})$$ for a non-rotated ellipse. But this doesn't work, of course, in the rotated case.
After following the link suggested by Minus One-Twelfth, this is what finally worked for me as a couple of Swift methods: