Using arctan / arctan2 to build a from 0 to 2π

I'm trying to reproduce the plot in Orbital Mechanics by Curtis, but I just can't get it. However, I made the main path by switching to np.arctan2 with np.arctan .

Perhaps I am executing arctan2 ?

 import pylab import numpy as np e = np.arange(0.0, 1.0, 0.15).reshape(-1, 1) nu = np.linspace(0.001, 2 * np.pi - 0.001, 50000) M2evals = (2 * np.arctan2(1, 1 / (((1 - e) / (1 + e)) ** 0.5 * np.tan(nu / 2) - e * (1 - e ** 2) ** 0.5 * np.sin(nu) / (1 + e * np.cos(nu))))) fig2 = pylab.figure() ax2 = fig2.add_subplot(111) for Me2, _e in zip(M2evals, e.ravel()): ax2.plot(nu.ravel(), Me2, label = str(_e)) pylab.legend() pylab.xlim((0, 7.75)) pylab.ylim((0, 2 * np.pi)) pylab.show() 

Gaps appear in the image below. The function should be smooth and connected at 0 and 2 pi in the range y (0, 2pi), without touching 0 and 2pi.

enter image description here

Graph and equation of the textbook:

enter image description here

enter image description here

At the request of Saulo Castro, they told me that:

"The problem may be with the arctan function, which gives" core values ​​"as output.

So arctan (tan (x)) does not give x if x is the angle in the second or third quadrant. If you draw arctan (tan (x)) from x = 0 to x = Pi, you will find that it has a discontinuous jump at x = Pi / 2.

In your case, instead of writing arctan (arg), I think you should write arctan2 (1, 1 / arg), where arg is the argument to your arctan function. Thus, when arg becomes negative, arctan2 will give an angle in the second quadrant, not the fourth.

+7
source share
1 answer
It is common practice to summarize 2 * pi in negative arctan() results that can be done efficiently . The OP clause for replacing arctan (x) with arctan2 (1,1 / x), also suggested in the Maple 15 documentation, as pointed out by @ Yay295, gives the same results without the need to sum 2 * pi. Both are shown below:
 import pylab import numpy as np e = np.arange(0.0, 1.0, 0.15).reshape(-1, 1) nu = np.linspace(0, 2*np.pi, 50000) x = ((1-e)/(1+e))**0.5 * np.tan(nu/2.) x2 = e*(1-e**2)**0.5 * np.sin(nu)/(1 + e*np.cos(nu)) using_arctan = True using_OP_arctan2 = False if using_arctan: M2evals = 2*np.arctan(x) - x2 M2evals[ M2evals<0 ] += 2*np.pi elif using_OP_arctan2: M2evals = 2 * np.arctan2(1,1/x) - x2 fig2 = pylab.figure() ax2 = fig2.add_subplot(111) for M2e, _e in zip(M2evals, e.ravel()): ax2.plot(nu.ravel(), M2e, label = str(_e)) pylab.legend(loc='upper left') pylab.show() 

enter image description here

+9
source

All Articles