dilevin / computer-graphics-raster-images

Computer Graphics Assignment about Raster Images
2 stars 10 forks source link

rgb to hsv conversion #98

Open lulu-yunze opened 2 months ago

lulu-yunze commented 2 months ago

Hello,

For rgb to hsv conversion I am using the formula from wikipedia: Screenshot 2024-09-17 195853

How do we deal with the case when (G-B)/C mod 6 is negative if R is the largest value?

Thank you very much.

TonyXiChen commented 2 months ago

The range of mod(a, b) for all (a, b) in the domain is [0, 5], keep adding 6 until the result falls in [0, 5].

lulu-yunze commented 2 months ago

I am using std::fmod and when (G-B)/C is negative, mod 6 returns a negative number. For example, if (G-B)/C = -0.2, then -0.2 % 6 = -0.2. What do I do in this situation? Should it return 0 instead of -0.2?