Trigonometry sin return negative

I made this code in Python

def hitsin(a):
    a = a*57.3
    return math.sin(a)

so whenever i put hitin (x), x is converted to radian. I confuse when I set hitin (90), the answer is not 1 or any number is about 1, but negative (it was -0.9971392129043587). Am I doing it wrong?

ps: I am also trying to write the same code in C

#include <stdio.h>
#include <math.h>

int main(){
    float degree;
    float result;

    degree = 90;
    degree = degree*57.3;
    result  = cos(result);

    printf("%f",result);

    return 1;
}

But the answer is the same.

sincerely your kettlebell

+3
source share
4 answers

You must divide by 180/pi, not multiply. In Python, you can also use math.radians()to convert from degrees to radians:

def hitsin(a):
    return math.sin(math.radians(a))
hitsin(90)
# 1.0

In addition, I doubt that the C code gives the same result as the Python code, because it uses cos()instead sin().

+12
source

57,3 ( 180/π), .

+6

You made a unit conversion error:

To convert degrees to radians:

radians = (2 * pi * degrees) / 360

What gives:

radians = degrees / 57.295... = degrees * 0.01745...
+1
source

Factor 57.29 ... is converted from radians to degrees. However, you need to do the exact opposite.

def degree_to_radian(x):
    from math import pi
    return x*pi/180

# pi/180 = 0.0174…

def degsin(x):
    from math import sin
    return sin(degree_to_radian(x))
0
source

Source: https://habr.com/ru/post/1790036/


All Articles