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.
I can see two possible problems here:
atan2takes the parameters in order (y,x) in every language I’m aware of. You passed in (x,y).cosandsintake parameters in radians, but you’re giving them in degrees. Remove the multiplication by 180/pi to keep the angle in radians.