How do you calculate the angle between one object and another assuming your first object is your origin and the up vector is, well up? I struggled with this problem in android and java for about six hours and there wasn’t any really good questions or answers that gave a correct way to calculate it.
If the question is not super clear:
I have an object on the screen and I want to know what the angle is from this object with up being the y axis (or 90 degrees) to another object on the screen. So if the first object is at 1,1 and the second object is at 2,2, then the angle should be 315. This is because 0 degrees is to the right, 90 degrees is up (y axis), 180 degrees is left, and 270 degrees is down.
There might be more elegant solutions, but I found this works well:
This gives the angle starting with 0 right, 90 up, 180 left, and 270 down. I answered my own question because it took me over a day to find this and it wasn’t on the internet. I hope it helps someone. I’ll leave the question unanswered for a day or two, to see if anyone can find a more elegant solution or a better way of expressing the answer. This answer is in java and has been tested on Android.