This might seem like pure math problem at first but it isn't.
Because this problem is unsolvable by standard algebraic math methods (no goniometrics will help at least we still do not know the correct answer/equation) as we simply do not know what the perimeter of ellipse is. All the equations you can find (the one you posted including) are just approximations suited for specific ranges of eccentricity (so they are not precise and their error is getting bigger for ellipses with different eccentricity)!!!
Integration along perimeter is possible (curve integral) however IIRC it leads to non integrable therms so you need to use numeric methods instead (where programming comes in).
The easiest method of computing arc-length is to convert your elliptic arc to set of very small lines and sum their lengths in some for
loop using parametric ellipse equation.
Now its just a matter of selecting the number of lines or method of numeric integration so you meet your accuracy requirements...
Orientation of ellipse is meaningless for this problem as your arc starts from major axis... so you can solve it as it is always axis aligned.
Here simple C++ example using the lines:
int e;
float a=?,b=?,ang=?,l,aa,da=0.001*M_PI,x,y,x0,y0;
aa=0.0; // starting angle
x=a*cos(aa); // starting point
y=b*sin(aa);
for (e=1,l=0.0;e;)
{
aa+=da; if (aa>=ang){ e=0; aa=ang; } // ending angle reached?
x0=x; x=a*cos(aa); // 2 consequent points on ellipse (line)
y0=y; y=b*sin(aa);
l+=sqrt(((x-x0)*(x-x0))+((y-y0)*(y-y0))); // add line length to arclength
}
where a,b
are your semi-axises, ang
is angular size of your arc and l
is your arc-length. The da
is the integration step the smaller it is the better accuracy but longer computation...
I typed this code directly in SO editor so it might contain syntax errors...
btw here few QAs related to ellipse perimeter problem for inspiration: