[英]How to determine magnitude of trigonometric function? C++
> if (((test>=0) && (test<=90)) || ((test>270) && (test<=360))){n_y=1;}
> else {n_y=-1;}
I need the magnitude of trigonometric function in order to determine the sign of the trigonometric function for an angle falling into a particular quadrant. 我需要三角函数的大小才能确定落入特定象限的角度的三角函数的符号。
My plan is to replace the code above with something equivalent. 我的计划是将以上代码替换为等效代码。
Here is what I want to do in pseudo-code. 这是我想用伪代码执行的操作。
n_y = cos(test) / (magnitude of cos (test));
This will give me same thing. 这会给我同样的事情。 Abs() only takes integers.
Abs()仅采用整数。 Any help is appreciated.
任何帮助表示赞赏。
I don't know what Abs()
you're using, fabs from the C++ standard takes doubles just fine . 我不知道您正在使用什么
Abs()
, C ++标准的fab需要两倍的精度 。
But you don't really want magnitude, because then you're stuck doing an expensive division. 但是您实际上并不需要幅度,因为那样您就不得不进行昂贵的划分。
Did you #include <cmath>
to get the floating-point overloads for abs
? 你
#include <cmath>
以获取浮点重载abs
?
As for finding the quadrant, if 0 <= test <= 360
, and you want to test 90 < test <= 270
just use 90 < test && test <= 270
. 至于寻找象限,如果
0 <= test <= 360
,而您想测试90 < test <= 270
只需使用90 < test && test <= 270
。 There is a continuous range between the two discontinuous ranges you are currently testing. 当前正在测试的两个不连续范围之间有一个连续范围。 However, your particular example defines things asymmetrically as it maps 0 => 1 and 270 => -1.
但是,您的特定示例在映射0 => 1和270 => -1时非对称地定义了事物。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.