# Finding angle of a line between two revolving points in two orbits, from one pont to other and not viceversa in JavaFX

I am new to JavaFX and really weak in Trigonometry and Math and have been trying to find the angle (of a line) between two points. These two points revolve in two circular orbits. These points represent Earth and Jupiter and I need to find the angle between Earth and Jupiter, to be exact, angle from Earth to Jupiter. Jupiter revolves in an orbit with higher radius as in our solar system. I tried ‘atan’ and ‘atan2’ but it doesn’t give expected answer for all angles, I am too dumb to use it properly. Upon further research I found out something like ‘ it only calculates the angle with respect to +ve side of X axis’, but I got the point. With further reading and help from ‘Slope Calculator’ (https://www.calculator.net/slope-calculator.html) I managed to solve that issue as they did. By adding appropriate degrees like 180,360 to the atan / atan2 results and getting correct and expected (by me) final results. This adding of 90/180/360 degrees (I haven’t seen them adding 90 degrees, or why would one want to add 0 degree) is not fully understood by me. My poor Math skills says its the difference of the measured angle (the old +ve x axis, 360/180 – measured angle ?) to 360 degrees, or simply put, the unmeasured angle (total of 180 or 360 degrees) The problem is, the results are not always the expected, rarely it goes wrong, very big differnce, totaly wrong. This is owing to the adding of wrong degrees to atan / atan2 results. The method used at the Calculator Site gives correct results, except for line of 180 degrees (3’O clock to 9’O clock line), it gives 0 degrees. (Shouldn’t be it 180 degrees? What ever, I need 180 degree for such a line). The site adds 180 degree or 360 degree to the result to get the final result and is correct and as per my requirement, expect for 3’O Clock —-> 9’O Clock line case. The angle for 9’O —> 3’O is correct and as per my requirement. Too figure out how much degrees to add to the atan / atan2 results, I am currently finding the slope of the line and adding 0/90/180/360 degrees to the atan / atan2 results and getting expected result even for 3’O clock —-> 9 ‘O clocok line. Still something is wrong.

`//PANE_HEIGHT is 960, the height and width of pane. PositionX is subtracted from it to get the //Cartesian plane coordinates instead of screen coordinates currentJupiterAngleRetroRough = (Math.toDegrees(Math.atan((((PANE_HEIGHT - jupiterPositionY) - ( PANE_HEIGHT-earthPositionY))) / ((jupiterPositionX) - (earthPositionX))))); //Finding the slope of the line slope = (((PANE_HEIGHT-jupiterPositionY) - (PANE_HEIGHT-earthPositionY)) / ((jupiterPositionX) - (earthPositionX))); //Adding required angles to output of atan to get final degrees,based on the slope currentJupiterAngleRetro = (Math.toDegrees( Math.atan((((PANE_HEIGHT - jupiterPositionY) - ( PANE_HEIGHT-earthPositionY))) / ((jupiterPositionX) - (earthPositionX) )))) + (slope<0 ? 360:(slope==0?0:(slope>0 & slope<1 ? 0:(slope>1 & slope<2 ? 90:180 )))); //Various approaches to find the appropriate degrees to add to atan result (slope<0 ? 360:180); (slope<0 ? 360:(slope==0?0:180 )); // Different One // Another one // and so on (slope<0 ? 360:(slope==0?0:(slope>0 & slope<1 ? 0:(slope>1 & slope<2 ? 90:180 )))); //Improved one, still not fully correct `

The app simulates the position of planets continuously for any date/time and continuously updates the position and degree in both graphics and text. So it is a time taking task to find if the calculations are wrong and I sure found it is, but very hard to find. Apart from that, the degrees which are to be calculated are of angle between planets that are retrograding (backward moving optical illusion), so way hard to spot the calculation errors. Will have to log all the original angles,positions,retro angles to console and ready line by line to see big jumps or will have the watch the original angle and calculate the retro angle approximately in mind and verify.

It took two complete days to find a almost-fully-correct working solution and cant longer pull my hair. Have read similar questions on StackOverflow and even someone had almost the same issue, but no answer I beleive, and the discussion were continued on chat but couldnt find more info. I hope it would be very easy for people who are good at math. Please provide a perfect solution. Thanks in advance.

Download script demo [LINK]Download script demo [LINK 2]

Download script demo [LINK 2]

This is owing to the adding of wrong degrees to atan / atan2 results. The method used at the Calculator Site (https://calculator-online.net/slope-calculator/) gives correct results, except for line of 180 degrees (3’O clock to 9’O clock line), it gives 0 degrees. (Shouldn’t be it 180 degrees? What ever, I need 180 degree for such a line).

Download demo