0

Given:

A point P, circle 1 and circle 2's positions and radii

What is:

The equation for T, the 'mix level' between color 1 and 2 (a value between 0 to 1)

Many radial gradient equations only apply to concentric circles or circles that share a position. I'm looking for something that matches the image below, created using Quartz (Core Graphics). I am writing a GLSL shader, but I need to understand the math first.

enter image description here

4

1 回答 1

1

如果这是二维的,那么您可以将您的点所在的圆的参数写为:

x3=T*x1+(1-T)*x2
y3=T*y1+(1-T)*y2
r3=T*r1+(1-T)*r2

编辑:当然,该圆圈可以表示为:

(x3-xP)^2+(y3-yP)^2=r3^2

您可以将前 3 个方程代入最后一个方程(并记住 (xP, yP) 是您的观点)以得到 1 个方程,其中只有 T 作为 T 中的二次变量,因此很容易求解 T。这样做给我们:

T=(-r2*(r1-r2)+(x1-x2)*(x2-xP)+(y1-y2)(y2-yP)
    {+-}sqrt(r2^2*((x1-xP)^2+(y1-yP)^2)-2*r1*r2*((x1-xP)*(x2-xP)
               +(y1-yP)*(y2-yP))+r1^2*((x2-xP)^2+(y2-yP)^2)
               -(x2*y1-xP*y1-x1*y2+xP*y2+x1*yP-x2*yP)^2))
 /((r1-r2)^2-(x1-x2)^2-(y1-y2)^2)

我知道这有点难以阅读,但在数学上实际上并没有那么糟糕。它只是加法、乘法和平方(实际上只是乘法)。

于 2012-12-22T00:03:32.147 回答