Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use atan2 instead of arccos where possible to improve accuracy #31

Open
rizsi opened this issue Aug 13, 2024 · 1 comment
Open

Use atan2 instead of arccos where possible to improve accuracy #31

rizsi opened this issue Aug 13, 2024 · 1 comment

Comments

@rizsi
Copy link

rizsi commented Aug 13, 2024

The use of arccos function to count angles from cartesian coordinates is not accurate when the angle is around 0 or 180 degrees. There the slope (derivative) of the cosine function is 0 so inverting it will be very inaccurate. We loose from the precision that we have in the cartesian coordinates. In the example code I would recommend to use atan2 everywhere it is possible. Besides the phase problem (which is rightly mentioned in the text several times) the accuracy is also a reason why using atan2 is the better choice to count the angle in almost all cases. We pass both the sine and the cosine value to the function and at least one of them will be at the part of the function which will yield high precision.

I would also like to send compliments. Your text on orbital mechanics really helps understanding and implementing the ideas necessary to simulate how the bodies move. It is by far the most complete and to the point document that I have found. Great work! I try to implement a KSP inspired game and this documentation is exactly what I need.

An example of the usage of arccos is here:

which is here in the document: https://orbital-mechanics.space/classical-orbital-elements/orbital-elements-and-the-state-vector.html#step-3inclination

@bryanwweber
Copy link
Owner

Thanks for reporting this! Feel free to update this section. I'd prefer to keep the arccos example for pedagogical purposes (and add a figure, but I don't expect you do to that 😉) , but adding a note and suggesting that atan2 is preferred from a practical standpoint would be very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants