开发者

How to determine magnitude of trigonometric function? C++

开发者 https://www.devze.com 2022-12-27 01:11 出处:网络
>if (((test>=0) && (test<=90)) || ((test>270) && (test<=360))){n_y=1;}
>     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 pla开发者_开发问答n 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. Any help is appreciated.


I don't know what Abs() you're using, fabs from the C++ standard takes doubles just fine.

But you don't really want magnitude, because then you're stuck doing an expensive division.

Instead just use a signum function.


Did you #include <cmath> to get the floating-point overloads for abs?

As for finding the quadrant, if 0 <= test <= 360, and you want to test 90 < test <= 270 just use 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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号