views:

41

answers:

1
double testx, testy, testdeg, testrad, endx, endy;

testx = 1;
testy = 1;
testdeg = atan2( testx, testy) / Math::PI* 180;  
testrad = sqrt(pow(testx,2) + pow(testy,2));
endx = testrad * cos(testdeg);
endy = testrad * sin(testdeg);

All parts of this seem to equate properly, except endx and endy should = testx and testy they do when calculating by hand.

+8  A: 

I can see two possible problems here:

  • atan2 takes the parameters in order (y,x) in every language I'm aware of. You passed in (x,y).
  • cos and sin take parameters in radians, but you're giving them in degrees. Remove the multiplication by 180/pi to keep the angle in radians.
interjay
Ahh wow, i WAS inputting degs into cos/sin not RADS. thank you
Smoka