C# 中的 Math.Atan2 或类实例问题

发布于 2024-08-15 17:27:45 字数 603 浏览 3 评论 0原文

这是我的问题(C#):

double Y = 0.0;
double X = -21.0;

double q1_Test = Math.Atan2(0.0, -21.0);               // gives Math.Pi
double q1_Test2  = Math.Atan2(( double)Y, (double)X);  // gives Math.Pi

double w1 = <SomeclassInstanceGlobalHere>.getW1();  // This is a class which updates a variable
double w2 = <SomeclassInstanceGlobalHere>.getW2();  // This is a class which updates a variable

double q1  = Math.Atan2(w2, w1);              // ** gives -Math.Pi ** ???
//w2 shows 0.0 and w1 shows -21.0

当我从另一个类获取值时,变量值分别为 0.0 和 -21.0。调试时它也会显示在 IDE 中。 这里出了什么问题?

Here is my problem (C#) :

double Y = 0.0;
double X = -21.0;

double q1_Test = Math.Atan2(0.0, -21.0);               // gives Math.Pi
double q1_Test2  = Math.Atan2(( double)Y, (double)X);  // gives Math.Pi

double w1 = <SomeclassInstanceGlobalHere>.getW1();  // This is a class which updates a variable
double w2 = <SomeclassInstanceGlobalHere>.getW2();  // This is a class which updates a variable

double q1  = Math.Atan2(w2, w1);              // ** gives -Math.Pi ** ???
//w2 shows 0.0 and w1 shows -21.0

When I get the values from the other class, variable values are 0.0 and -21.0 respectively. It also shows in the IDE while debugging.
What is going wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨后彩虹 2024-08-22 17:27:45

w2 实际上必须为 -0.0,其格式为 0

以下博客文章展示了如何实际测试此值 (Decimal.GetBits(value)):
http:// blogs.msdn.com/bclteam/archive/2006/10/12/decimal-negative-zero-representation-lakshan-fernando.aspx

w2 must actually be -0.0, which is formatted as 0

The following blog post shows how you can actually test for this (Decimal.GetBits(value)):
http://blogs.msdn.com/bclteam/archive/2006/10/12/decimal-negative-zero-representation-lakshan-fernando.aspx

往昔成烟 2024-08-22 17:27:45

请注意,对于三角学而言,-Math.PI 和 Math.PI 是等效的。将角度当作双倍角度进行比较几乎总是一个非常糟糕的主意。请参阅扩展的 SO 讨论:再次平均角度

Note that -Math.PI and Math.PI are equivalent for the purposes of trigonometry. It is almost always a very poor idea to compare angles as if they were doubles. See extended SO discussion: Averaging angles... Again

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文