title: Categorize a random color into one of the primary colors Windows Phone
body: <p>I am trying to create a method that accepts a random color value then check which primary colors it's closest to.</p>
  
  <p><img src="https://i.stack.imgur.com/LxtRS.png" alt="enter image description here"></p>
  
  <p>I imagine I have to compare its RGB value and see where it falls within the range of those primary colors and then set it as Red, or Yellow or Blue etc.</p>
  
  <p>What is the best way of doing this? Thanks</p>
  
  <p><strong>EDIT</strong>
  This question is marked as duplicate but I checked the other answer of the said duplicate question but it doesn't offer the answer I am after.</p>
  
  <p>using the formula </p>
  
  <pre><code>d = sqrt((r2-r1)^2 + (g2-g1)^2 + (b2-b1)^2)
  </code></pre>
  
  <p>sometimes produce the same value for different colors. For instance take an input color of <code>R170 : G0 : B255</code>.  The distances from both white <code>R255 : G255 : B255</code> and red <code>R255 : G0 : B0</code> produce (int)269 using the formula. So which color is closer, red or white? I removed black and white from the list but the problem still occurs for some other colors.</p>
  
  <p>I am comparing with several colors  i.e:  black, white, red, lime. blue, yellow, cyan. magenta and gray as listed in the RGB color table here rapidtables.com/web/color/RGB_Color.htm </p>