Please Help with Atan2, Excel vs C# Why is my code broken!

So I am working on an IK calculation and in Excel I get a sucessful calculation with expected results, in c# using the same numbers I get a different result!

Here is the Excel code:
Xb= -0.88
Zb= -0.37
Q= 0.30

P1= Atan2(Xb-QZb, Zb+QXb)*180/PI()
P1=-140.80

Here is the C# code:

Xb= -0.88
Zb= -0.37
Q= 0.30

P1 = Math.Atan2(Xb - Q * Zb, Zb + Q * Xb) * 180 / Math.PI ;
P1=-129.19

Why am I getting two different results? Is there a difference between the Atan2 in Excel and the Atan2 in C#?

this is really driving me nuts!

Thanks for any help!!

Sorry, I don’t use C# much, but a quick look at the two help files have:
in excel atan2(x, y) and in c# it has math.atan2(y, x).

So have you tried reversing your parameters?

Also I don’t remember how well excel has for operator ordering. So you may also want to try using parens () around parts of the expressions to see if the operator order is correct.

Kurt

That fixed it, so many lines of code, it’s the little things that keep messing me up!

Thanks!

Hi, I have similar problem. Can you let me know how did you fix the issue ? I am getting different values in Excel and in Visual Studio. ?