POV-Ray : Newsgroups : povray.advanced-users : L*C*h(uv) color solid : Re: L*C*h(uv) color solid Server Time
26 Jun 2024 00:47:14 EDT (-0400)
  Re: L*C*h(uv) color solid  
From: Mike Horvath
Date: 19 Nov 2016 22:47:36
Message: <58311cd8$1@news.povray.org>
I'm having a problem converting between units. Here is the code I'm 
trying to adapt to POV-Ray:

	https://github.com/THEjoezack/ColorMine/blob/master/ColorMine/ColorSpaces/Conversions/LchConverter.cs

         internal static IRgb ToColor(ILch item)
         {
             var hRadians = item.H * Math.PI / 180.0;
             var lab = new Lab
                 {
                     L = item.L,
                     A = Math.Cos(hRadians) * item.C,
                     B = Math.Sin(hRadians) * item.C
                 };
             return lab.To<Rgb>();
         }

Here is the POV-Ray version I created:

	// input L = between 0 and 100
	// input C = between 0 and 100
	// input H = between 0 and 360
	// output L = between 0 and 100
	// output A = between -128 and +128
	// output B = between -128 and +128
	#macro CLCH2LAB(Color)
		#local LCHFT = color Color;
		#local L = LCHFT.red;
		#local C = LCHFT.green;
		#local H = LCHFT.blue;
		#local hRadians = radians(H);
		#local A = cos(hRadians) * C;
		#local B = sin(hRadians) * C;
		<L,A,B>
	#end

When I plug the vector <50,50,180> into this function I get 
<50.00000,-50.00000,0.00000> as a result. However, the Web converter 
(http://colormine.org/convert/lch-to-lab) says it should be 
<51.622535970468874,-37.18943330724933,2.558221480506817>

It's a simple function. I don't see anything obvious that is wrong with 
it. Do you?

Mike


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.