title: Calculate colour temperature in K
body: <p>I have written a lib for working with colours and stuck trying to calculate <code>Tc(k)</code>. From what I have read working in the <a href="http://en.wikipedia.org/wiki/CIE_1931_color_space" rel="noreferrer">CIE 1931</a> <code>XYZ</code> colour space is the way to go and it can be obtained using <code>xyY</code>.</p>
  
  <p>So far I have got everything correct to the point of figuring out the correct <code>x</code> and <code>y</code> from :</p>
  
  <pre><code>          X                 Y
  x = ____________  y = ____________
      ( X + Y + Z)      ( X + Y + Z)
  </code></pre>
  
  <p>The numbers much up to the chart, but cant find anything that details how you go from <code>x</code> and <code>y</code> to <code>Tc(K)</code></p>
  
  <p><img src="https://i.stack.imgur.com/KwAFc.png" alt="enter image description here"></p>
  
  <p>eg: For #FF0000 I get the following.</p>
  
  <pre><code>x: 0.64007449945677
  y: 0.32997051063169
  </code></pre>
  
  <p>I have read a number of papers on the topic and litterally all the wikipedia articles. All the questions I have come across on SO simply link to a wiki article on colours, not seen one that has the actual formula for calculating <code>Tc(k)</code></p>