HSV三角形中的公式 [英] The formulars in HSV triangle
问题描述
我不知道以下两个公式是如何得出的.请解释一下.我的名声太低,以至于我不能问那个公式的编写者.
I do not know how the following two formulas are derived. Please kindly explain. My reputation point is so low that I can't ask the person who wrote the formula.
var sat = (1 - 2*y1) / (sqrt3*x1 - y1 + 2);
var val = (sqrt3*x1 - y1 + 2) / 3;
推荐答案
转换后,我需要三角形的角触摸单位圆的<0,-1>
"top",<-√3/2,1/2>
"bottom-left "和<√3/2,1/2>
右下".我选择左下角为黑点( val = 0),当 val = 1时,顶部为色点( val = 1和 sat = 1),右下角是白点( val = 1和 sat = 0)
After the transformation, I needed the corners of the triangle to touch the unit circle at the points <0,-1>
"top", <-√3/2,1/2>
"bottom-left" and <√3/2,1/2>
"bottom-right". I picked bottom-left to be the black point (val = 0), and when val = 1, the top would be the color point (val = 1 and sat = 1), and the bottom-right would be the white point (val = 1 and sat = 0).
为此,我首先将右边缘定义为方程式
To achieve this, I first defined the right edge as the equation
<x,y> = <0,-1>*sat + <√3/2,1/2>*(1-sat)
^ ^-- When sat = 0, the result is this point
'-- When sat = 1, the result is this point
然后,当 val 变为零时,我将这条线向<-√3/2,1/2>
缩放
I then scaled this line towards <-√3/2,1/2>
when val goes to zero
<x,y> = ( <0,-1>*sat + <√3/2,1/2>*(1-sat) )*val + <-√3/2,1/2>*(1-val)
<x,y> = <0,-1>*sat*val + <√3/2,1/2>*(1-sat)*val + <-√3/2,1/2>*(1-val)
^ ^ ^-- When val = 0, the result is this point
| '-- When val = 1 and sat = 0, the result is this point
'-- When val = 1 and sat = 1, the result is this point
从矢量形式转换:
x = 0*sat*val + √3/2*(1-sat)*val + -√3/2*(1-val)
y = -1*sat*val + 1/2*(1-sat)*val + 1/2*(1-val)
扩展:
x = -√3/2*val*sat + √3*val - √3/2
y = -3/2*val*sat + 1/2
重新排列:
(√3*x - y + 2)/3 = val
(1 - 2*y)/3 = sat*val
求解 sat 和 val :
sat = (1 - 2*y)/(√3*x - y + 2)
val = (√3*x - y + 2)/3
这篇关于HSV三角形中的公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!