How to find midpoint of an arc in MATLAB

It is necessary for me to find midpoint of some arc in MATLAB. For simplicity let this arc is a part of circle. Also, we know the radius, center and starting point and ending point of the arc. I used $atan2(y,x)$ to get the angle for each line constructed by start and end points. Then find $t_{mid}=\frac{t_1+t_2}{2}$ and use $x_{mid}=r*cos(t_{mid})+xc,~y_{mid}=r*sin(t_{mid})+yc.$ But the problem is that $atan2$ gives the angle between $-\pi$ and $\pi$. Then for example for third quarter if $t_1=\pi$ and $t_2=-\pi/2$, $t_{mid}=\pi/4$ and it is not true. If I add $2\pi$ to the angles lower than zero, then I have the same problem for fourth quarter, for example $t_1=\frac{3\pi}{2},t_2=0$, the mid angle is $\frac{3\pi}{4}$!!. How can I solve this problem?

• The problem is not with $atan2$ but is in the identification and then evaluation of $t_{mid}$: Imagine both the endpoints and the center lie on the same line (let's say the x axis), how do you decide which is the arc to draw? Maybe your question can be reworded in find the midpoint of the smallest arc between two points, in this case, evaluate $\Delta t=t_1-t_2$, add or subtract $\pi$ until $|\Delta t|<\pi$ and then $t_{mid}=t_1-\Delta t/2$.
– N74
Sep 9, 2016 at 12:36

Compute the coordinates of the midpoint $I$ of the endpoints (which is outside of the arc, of course): its polar angle is the same as the polar angle of the point you are looking for. The rest is easy.