High im making a vector class and i need to be able to convert from rectangular components to polar components and back again. The issue im having is that when i convert from polar to rectangular the numbers are not correct.
Here is the code for my polar to rectangular calculations
---------------------------------------------------------
xerzi im not sure what you mean?
The variable angl is entered as degrees by the user.
The formula to convert degrees to radians is: radians=angl*(180/pi)
so im converting a degree value into radians for the cos/sin math function then im calling
ither sin or cosin and multiplying by the magnitude to find an x or y value.
The problem is that when i enter (2,2) in rectangular mode i get 2.82843 ∠45
now if i set mag=2.82843 and angl=45, y=mag*sin(angl*180/3.14159265);
it should result in x=2 , y=2 but it does not and i dont know why.
The formula to convert degrees to radians is: radians=angl*(180/pi)
That is not the formula to convert degrees to radians, it's to convert radians to degrees which is why you aren't getting the values you want.
PI radians == 180 degrees, if you want to get the number of radians per degree:
Radians / Degree
so
Degree * (Radians / Degree)
Degree cancels out and you are left with radians
What you are calculating is this:
Degree * (Degree / Radians)
Which is:
Degree^2 / Radians
So therefore you are not actually inputting radians into your sin and cos functions which is why you don't get the result you want and which is why I posted this:
y=mag*sin( angl * (3.14159265 / 180) );
If you take in a value as a degree you should only convert it once and store it in radians, not store it in degrees than each time you need to use the value convert it to radians. Just a matter of opinion I guess, it's up to you though.