# ToPolarCoordinates not working with units

I am trying to convert some quantities with units from rectangular to polar coordinates (to get the magnitude and angle). It seems that ToPolarCoordinates command does not calculate the angle when units are present. Does anyone have a solution to this (other than removing the units)?

N1 = Quantity[1.0, "Newtons"];
N2 = Quantity[2.0, "Newtons"];
ToPolarCoordinates[{N1, N2}]


The output is:

M1 = 1.0;
M2 = 2.0;
ToPolarCoordinates[{M1, M2}]


The output is:

I am not sure whether ArcTan of two quantities with compatible units should work by default, but you can certainly make it work yourself.

Unprotect[ArcTan];
ArcTan[q1_Quantity, q2_Quantity] :=
ArcTan[QuantityMagnitude[q1], QuantityMagnitude[UnitConvert[q2, QuantityUnit[q1]]]]
Protect[ArcTan];

N1 = Quantity[1.0, "Newtons"];
N2 = Quantity[2.0, "Newtons"];
ToPolarCoordinates[{N1, N2}]

(* {Quantity[2.23607, "Newtons"], 1.10715} *)


Your issue is Mathematica cannot handle the units directly, so you need to extract the magnitudes, convert those magnitudes to polar, and reattach the units like so:

N1 = Quantity[1.0, "Newtons"];
N2 = Quantity[2.0, "Newtons"];

N1Value = QuantityMagnitude[N1];
N2Value = QuantityMagnitude[N2];

polarCoordinates = ToPolarCoordinates[{N1Value, N2Value}];

magnitude = Quantity[polarCoordinates[[1]], "Newtons"]
angle = Quantity[polarCoordinates[[2]], "Degrees"]*180/Pi

Out[10]= 2.23607 N
Out[11]= 63.4349 deg


You can change angle if you want rad.