I calculated the angle of (-6/35)
by using atan2(-6/35)
.
The result is -9.7275785514016047
.
Now to get back I used the formula from Wikipedia
distance = sqrt(6*6+35*35);
angleRelativeToPatternOrigin = -9.7275785514016047;
double x1 = distance * cos(angleRelativeToPatternOrigin);
double y1 = distance * sin(angleRelativeToPatternOrigin);
I exptected to get the coordinares (-6/35)
But I got (-33.895012797701419/10.589056022311761
)
So I think this is wrong because atan2
is defined over 4 quadrants and sin
and cos
are only defined over 2.
Is this correct? How to do it right?
Edit:
Now, first of all I am sorry for describing my question in a bad way. I actually did the following
int main(int argc, char* argv[])
{
int x = -6;
int y = 35;
double radian = atan2(x,y); // this was wrong. atan2(y,x) is correct.
double degree = radian * (360 / (2 * 3.14159265358979323846));
double distance = sqrt(6*6+35*35);
double x1 = distance * cos(degree); // Wrong because I used degree
double y1 = distance * sin(degree); // instead of radian
return 0;
}