0

So if I have a circle ranging from red to violet(0-360), can I get a colour if I have an angle? I have been searching but I have only found code to convert from different formats and nothing really to do with angles. I would really like to know the math that goes behind this.

I'm just writing a c++ program for my arduino with a joystick and an RGB led. I've got the easy stuff done but I don't even know where to begin with the colour.

Enter Name
  • 13
  • 1
  • 5
  • the angle starts at a common point, use if statements to see if angle is between range, If this is wrong I dont understand your question – omkaartg Mar 31 '18 at 05:52
  • 1
    This sounds like you are looking for [HSV](https://en.wikipedia.org/wiki/HSL_and_HSV) where H (Hue) is the angle you have given, S (Saturation) is 1 and V (Value) is 1. – Scheff's Cat Mar 31 '18 at 05:55
  • Converting to HSV format is relevant to the question, since the hue (in HSV) is represented as an angle on a circle. Marking as duplicate accordingly. – Peter Mar 31 '18 at 06:04

1 Answers1

2

The RGB color space is based on cartesian coordinates. If you want an angle that means you want something akin to polar coordinates, the color spaces you are looking for is either HSL or HSV.

https://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV

In HSV, you can for example use maxium Saturation and maxium Value, then you only have to pick the Hue (which is an angle).

That being said, you can also make-up one and use for example:

(R, G, B) = (256*cos(x), 256*cos(x + 120), 256*cos(x - 120))

Where cos is using degrees.

Nonyme
  • 1,220
  • 1
  • 11
  • 22