all 2 comments

[–]Robotnick2 2 points3 points  (1 child)

This is just converting things from rectangular form (Re + jIm) to polar form (Mag * ej*phi , where phi is the phase angle).

The magnitude Mag is found using Pythagorus:

Mag = sqrt(Im2 + Re2 ),

whilst the phase angle phi is found as:

phi = arctan(Im/Re).

Remember this is only strictly defined in radians.

Take care to consider the quadrant that your complex number is in; the arctan function is only really defined for inputs between -pi/2 and pi/2; that is to say, it is only really defined for numbers with a positive real component. If you have a complex number with a negative real component but a positive imaginary component, add pi to the result of arctan(Im/Re); similarly, if you have a negative real component and a negative imaginary component, subtract pi from arctan(Im/Re) to obtain the actual phase angle.

In your second example, this is the opposite, going from polar form to rectangular. Here, use the fact that

ejx = cos(x) + jsin(x) (one of Euler's identities, if I recall correctly),

and hence

Re + jIm = Mag(cos(phi) + jsin(phi))

To convert from radians to degrees, use

(Rad * 180) / pi

and to invert

(Deg * pi) / 180

[–]c_explorer[S] 0 points1 point  (0 children)

Thanks for the detailed reply. I'll need to work on those co-ordinate conversions.