This question is basically a follow-up or generalization of How to determine the arc length of ellipse?
Given an ellipse with axes a and b, and the start and end angles $\theta_{start}$ and $\theta_{end}$ of an arc, find the length of the arc.
I can follow the accepted answer on that question, but the solution it gives for finding the integration limits
$$t=\arctan \left( \frac{a}{b}\tan \theta \right)$$
only works when the arc is contained in the first (top-right) quadrant. When the angles are in other quadrants I end up with negative values for t. I'm at a loss what I need to change to correctly handle angles in other quadrants.
Once the Cartesian coordinates of the point in question have been calculated:
$$ (x_p,\,y_p) = \frac{a\,b}{\sqrt{\left(a\,\sin\theta\right)^2 + \left(b\,\cos\theta\right)^2}} \,\left(\cos\theta, \, \sin\theta\right) $$
with $a, \, b > 0, \, 0 \le \theta < 2\pi$ known parameters, essentially two cases can arise.
$$ t = \text{arctan2}\left(x_p/a, \, y_p/b\right) $$
i.e.
$$ t = \begin{cases} \arctan\left(\frac{y_p/b}{x_p/a}\right) - \pi & \text{if} \; x_p < 0 \, \land \, y_p < 0 \\ \arctan\left(\frac{y_p/b}{x_p/a}\right) + \pi & \text{if} \; x_p < 0 \, \land \, y_p \ge 0 \\ -\frac{\pi}{2} & \text{if} \; x_p = 0 \, \land \, y_p < 0 \\ \frac{\pi}{2} & \text{if} \; x_p = 0 \, \land \, y_p > 0 \\ \arctan\left(\frac{y_p/b}{x_p/a}\right) & \text{if} \; x_p > 0 \end{cases} $$
therefore, known the integration extremes $t_1 \le t_2$, the length of the ellipse arc is equal to:
if the arc does not cut the negative semi-axis of x: $$ \mathcal{L} = \int_{t_1}^{t_2} \sqrt{\left(a\,\sin t\right)^2+\left(b\,\cos t\right)^2}\,\text{d}t \,; $$
if the arc cuts the negative half-axis of x: $$ \mathcal{L} = \int_{-\pi}^{t_1} \sqrt{\left(a\,\sin t\right)^2+\left(b\,\cos t\right)^2}\,\text{d}t + \int_{t_2}^{\pi} \sqrt{\left(a\,\sin t\right)^2+\left(b\,\cos t\right)^2}\,\text{d}t \,. $$
$$ t = \begin{cases} \text{arctan2}\left(x_p/a, \, y_p/b\right) + 2\pi & \text{if} \; \text{arctan2}\left(x_p/a, \, y_p/b\right) < 0 \\ \text{arctan2}\left(x_p/a, \, y_p/b\right) & \text{if} \; \text{arctan2}\left(x_p/a, \, y_p/b\right) \ge 0 \\ \end{cases} $$
i.e.
$$ t = \begin{cases} \arctan\left(\frac{y_p/b}{x_p/a}\right) + \pi & \text{if} \; x_p < 0 \\ \frac{3\pi}{2} & \text{if} \; x_p = 0 \, \land \, y_p < 0 \\ \frac{\pi}{2} & \text{if} \; x_p = 0 \, \land \, y_p > 0 \\ \arctan\left(\frac{y_p/b}{x_p/a}\right) + 2\pi & \text{if} \; x_p > 0 \, \land \, y_p < 0 \\ \arctan\left(\frac{y_p/b}{x_p/a}\right) & \text{if} \; x_p > 0 \, \land \, y_p \ge 0 \end{cases} $$
therefore, known the integration extremes $t_1 \le t_2$, the length of the ellipse arc is equal to:
if the arc does not cut the positive semi-axis of x: $$ \mathcal{L} = \int_{t_1}^{t_2} \sqrt{\left(a\,\sin t\right)^2+\left(b\,\cos t\right)^2}\,\text{d}t \,; $$
if the arc cuts the positive half-axis of x: $$ \mathcal{L} = \int_{0}^{t_1} \sqrt{\left(a\,\sin t\right)^2+\left(b\,\cos t\right)^2}\,\text{d}t + \int_{t_2}^{2\pi} \sqrt{\left(a\,\sin t\right)^2+\left(b\,\cos t\right)^2}\,\text{d}t \,. $$