Calculating offset from Planckian locus

I'm calculating the Correlated Color Temperature (CCT) from a chromacity pair, and I am trying to find how far from the Planckian Locus the coordinates are.

What I'm currently doing is I read RGB values off a sensor, I do a matrix transformation to get to XYZ. Then I calculate the xy values, and lastly I use McCamy’s formula to get CCT.

McCamy’s formula gives me the Correlated Color Temperature, the nearest point along the Planckian Locus for the xy coordinates (roughly a orange to blue axis). I am trying to find the green/magenta content of the light, so I need to find how far from the locus the coordinates are (roughly a green to magenta axis).

I guess McCamy’s formula finds the normal down to the locus, and that I need to calculate how long that normal is. I also have to do it fast (this is running on a small embedded processor). I'm using the CIE 1931 color space. (EDIT: The illustration is from CIE 1960 as pointed out below, but I could not find a chart showing isothermal lines for CIE 1931) I'm a bit confused because you write that you calculate the CCT using $xy$ values using McCamy's formula (I'm assuming you mean this formula), but you included a diagram of the Planckian locus in $uv$, not in $xy$. Presumably when you say you're trying to find how far from the Planckian locus the coordinates are, you're referring to the Euclidean distance either in $xy$ space or in $uv$ space? In either case, this section has approximations where you can plug in the CCT to get the corresponding coordinates on the Planckian locus; then you just have to calculate the Euclidean distance of your point from that point using Pythagoras. I guess since you're already approximating by using McCamy's formula, this further approximation will be OK; if not, you can always do a full summation over the standard observer as shown further up in the article.