- #1
Ostsol
- 12
- 0
I have recently experimented with algorithms for rendering colour gradients. Linear gradients are no problem, but radial gradients have proved to be somewhat more difficult. A radial gradient focused at the centre is simply a matter of measuring the distance of a pixel from the centre and comparing it to the radius of the gradient. I found that the most elegant solution was to represent the gradient as an inverted cone of height 1.0. This way, with a single equation I can discover the ratio with which to interpolate colours. I used the following quadric surface equation:
[itex]\frac{x^{2}}{a^{2}} + \frac{y^{2}}{b^{2}} - \frac{z^{2}}{c^{2}} = 0[/itex]
Solving for z, I get the ratio.
The problem is that this works only for right circular or elliptical cones. If the apex is not above the centre, as with an oblique cone, this equation will not help me. I need this because a radial gradient's focus need not be at its centre. I can discover the ratio via a line-circle intersection, but I feel that representing the gradient as an oblique cone would be more elegant and probably more efficient. Unfortunately, I cannot find any information on how one might graph such a cone and my math education is limited to introductory single-variable calculus -- and that was over a decade ago. As such, deriving the correct equation myself is beyond me.
Can anyone help me find such an equation, assuming one exists?
I have attached an example of the kind of radial gradient I would like to reproduce.
[itex]\frac{x^{2}}{a^{2}} + \frac{y^{2}}{b^{2}} - \frac{z^{2}}{c^{2}} = 0[/itex]
Solving for z, I get the ratio.
The problem is that this works only for right circular or elliptical cones. If the apex is not above the centre, as with an oblique cone, this equation will not help me. I need this because a radial gradient's focus need not be at its centre. I can discover the ratio via a line-circle intersection, but I feel that representing the gradient as an oblique cone would be more elegant and probably more efficient. Unfortunately, I cannot find any information on how one might graph such a cone and my math education is limited to introductory single-variable calculus -- and that was over a decade ago. As such, deriving the correct equation myself is beyond me.
Can anyone help me find such an equation, assuming one exists?
I have attached an example of the kind of radial gradient I would like to reproduce.