in reply to A data selection problem(in3D).
When doing a two-dimensional "s" shaped (sigmoid) curve, I often use a polynomial sigmoid*,**: f(x) = 3*x**2 - 2*x**3, 0 <= x <=1. You can also do similar 2-d "s" with higher-order polynomials. The general procedure is to take the general n-th order polynomial function, then define n+1 boundary conditions; it's useful to take enough derivatives to help with your boundary conditions. Then solve those n+1 equations for the n+1 arbitrary parameters to complete your For example, the cubic "s" above is defined as
f(x) = a*x**3 + b*x**2 + c*x + d f'(x) = 3*a*x**2 + 2*b*x + 1*c f(0) = 0 # start at 0 f'(0) = 0 # want a flat slope f(1) = 1 # end at 1 f'(1) = 0 # but flat at this end, as well. solve: d = 0 # from f(0) c = 0 # from f'(0) b = 3, a=-2 # from f(1) and f'(1)
... and a quintic version would also define the second derivatives at 0 and 1 as 0. I've also done similar ones where I constrain the endpoints less, and instead move the center (so f(0.5) = 0.75 or f(0.8)=0.5 or similar). Some caveats is that it's really easy to accidentally define a function whose output goes beyond 0 or 1 while still inside the range of x, so sometimes I use inequalities to bound the output, though that gets more difficult to solve.
This should be extensible into 3 dimensions:
f(x,y) = a*x**2 + b*y**2 + c*x*y + d*x + e*y + g f(0,0) = 0 f(1,1) = 1 df/dx(0,0) = 0 df/dy(0,0) = 0 df/dx(1,1) = 0 df/dy(1,1) = 0
(I don't know what shape that would make... I haven't gone thru and solved it). You would need to define boundary conditions that made sense for your HSV.
Actually, maybe it's simpler than that: maybe you just want a parameter "p", which maps through three separate functions
p:0..1 H(p) = a*p**3 + b*p**2 + c*p**1 + d I would recommend corners like: H(0) = Hmin H'(0) = 0 H(1) = Hmax H'(1) = 0 to get a similar "s" shape to 3*x**2 - 2*x**3, but scaled so the o +utput go from the min to the max you want S(p) = e*p**3 + f*p**2 + g*p**1 + h S(...) = Smin, 0, Smax, 0 V(p) = j*p**3 + k*p**2 + m*p**1 + n V(...) = Vmin, 0, Vmax, 0
If you change the p=0..1 domain to whatever matches your domain of your gold scale (ie, if you determine the shade of gold by the height on your screw, or at least the height between screw threads -- I forget which from your previous discussion -- then your p would be equal to your height, and you would just define the p corners as height-min and height-max instead of 0 and 1). Thus, with a linear progression thru your p-parameter, you should get a nice "s"-shaped progression for each of your H, S, and V.
--
*: technically, a true Sigmoid function will asymptotically approach 0 and 1 off toward infinite-x, and will be centered at x=0. This "polynomial sigmoid" was chosen back in Perlin's early days as a "good enough approximation" that was easy to compute/pre-compute on his old 80s computers.
**: I think I first encountered either in my neural network class back in the 90s, or when looking into Perlin noise for fun sometime thereafter.
EDIT 1: fixed the H,S,V cubics' last terms...
EDIT 2: change the last term of f(x,y) from an f (confusing) to a g (unambiguously different than f(x))
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: A data selection problem(in3D).
by pryrt (Abbot) on Apr 06, 2017 at 15:17 UTC | |
Re^2: A data selection problem(in3D).
by BrowserUk (Patriarch) on Apr 07, 2017 at 05:47 UTC | |
Re^2: A data selection problem(in3D).
by BrowserUk (Patriarch) on Apr 06, 2017 at 16:29 UTC | |
Re^2: A data selection problem(in3D).(Dammit! New requirement.)
by BrowserUk (Patriarch) on Apr 07, 2017 at 22:49 UTC | |
by pryrt (Abbot) on Apr 08, 2017 at 00:01 UTC | |
by BrowserUk (Patriarch) on Apr 08, 2017 at 02:06 UTC | |
by BrowserUk (Patriarch) on Apr 08, 2017 at 11:43 UTC |