Enjoy BYOND? Contribute today!
fat-peaked cosine graph
Jan 19 2012, 3:55 pm
Excuse my badly drawn cosine graph.
Is it possible? If so, how?
Jan 19 2012, 4:52 pm
By dividing within the cosine function (e.g. cos(x/3)) you can increase the wavelength between the waves, but I don't think there's any way you'll get anything near as drastic as what you've drawn there. The second drawing looks more like a square wave than a sine wave.
What you're trying to get isn't really lengthening the wavelength either. It's more like stunting the apex of the sin wave.
Jan 19 2012, 7:33 pm (Edited on Jan 19 2012, 8:39 pm)
Jan 19 2012, 9:40 pm
One option is taking an odd root of the function. Cubing for example would tend to pull values close to 1 farther away from 1, whereas you want to push values away from 0, so a cube root could do the trick. (You might need some special logic to account for the 0 case, possibly also the negative cases, depending on how the math is implemented.)
Another option is to feed one sine wave into another. sin(x + sin(2x)/2) produces some fatter peaks.
Jan 20 2012, 12:07 pm (Edited on Jan 20 2012, 12:31 pm)
In response to
To generate the functions in my post, take a sigmoid -1<=s(x)<=1 where roughly f(0)=0, f(1)=1, f(-1)=-1, and feed cos(x) to it to get the function s(cos(x)). This works because f(cos(x)) would 'stay' at the 1 or -1 when cos(x) is close to 1 or -1 respectively, and rapidly approach 0 as cos(x) approaches 0.
Incidentally you can take apart the function sin(x+sin(2x)/2) in the same way; sin(x+sin(2x)/2)=sin(x+sin(x)cos(x)), which is f(sin(x)) for f(x)=sin(arcsin(x)+x*cos(arcsin(x)) - a nice sigmoid in -1 to 1.
Jan 20 2012, 1:54 pm
In response to
That's an interesting technique. Using sigmoids actually you have a lot of flexibility.
In a sigmoid, s(nx) = s(x)^n / (s(x)^n + s(-x)^n), where s(-x) = 1 - s(x).
If you take sin(x) and rescale it into a sigmoid 0 to 1 range, you can apply this formula to push the values further out toward the extremes.
y = sin(x)
s = (y+1)/2
y' = 2(s^n / (s^n + (1-s)^n))) - 1
y' = 2((y+1)^n / ((y+1)^n + (1-y)^n))) - 1
n = 2
y' = 2((y+1)^2 / ((y+1)^2 + (1-y)^2))) - 1
y' = 2((sin^2(x) + 2sin(x) + 1) / (2sin^2(x) + 2)) - 1
y' = (sin^2(x) + 2sin(x) + 1) / (sin^2(x) + 1) - 1
y' = 2sin(x) / (sin^2(x) + 1)
You can use any value of n, though n=2 is simplest if you want a nice easy formula.
Copyright © 2014 BYOND. All rights reserved.
Terms of Service