LilahMcC / NarwhalHR

0 stars 1 forks source link

Use atan2 #11

Open FlukeAndFeather opened 2 years ago

FlukeAndFeather commented 2 years ago

Use atan2() instead of atan(). The way you're using atan() can lead to a bug in one case (and may be why you're getting some NaNs). Look it up on Google (or whatever search tool you prefer) and put the reason in this thread.

https://github.com/LilahMcC/NarwhalHR/blob/706112e60d29dd9f5ad5e564f8ea65b90017b799/util.R#L55

LilahMcC commented 2 years ago

I am not 100% sure on this one, so if you can double check my code to see if I implemented it correctly, that would be great. I think atan() just takes the overall sign of the y/z term to calculate the value, while atan2() considers the signs of each variable independently, which puts the result in the correct quadrant.