PDA

View Full Version : sin(); and cos(); dont work correctly! (math.h) Help me please



stinkee2
July 23rd, 2009, 02:32
Im trying to get points of a circle using sin() and cos()...
I did it on the calculator like this
x = circle x + radius * cos(angle)
y = circle y + radius * sin(angle)

x = 240 + 60 * cos(180);
y = 136 + 60 * sin(180);

on the caluculator I get
x = 180 (correct)
y = 136 (also correct)

but when I use the psp's math.h sin() and cos() I get
x = 204
y = 87
???
any Ideas on what is causing this
maybe its a stupid mistake I made, here are the functions I use to get both the x and y values:

int GetCircleCoordX(int x,int r,int angle)
{
return x + r * cos(angle);
}
int GetCircleCoordY(int y,int r,int angle)
{
return y + r * sin(angle);
}

yaustar
July 23rd, 2009, 12:05
Sin and cos functions in cmath/math.h use radians, not degrees.