🔒 Locked
Random Sine Wave?
Advertisement
Original Post
You can just throw together some random sine waves like A*sin(a*x) + B*sin(b*x) + C*sin(c*x) etc where A,B,C,a,b,c are just random numbers or something.
Preferably where A + B + C = 1.
You can add or multiply sine and cosine waves, with random amplitudes, periods, and phases. Most methods involve some baseline wave and have a pattern to how the subsequent waves are combined.
For instance, you might increase the period and reduce the amplitude by a coefficient of two for the next waveform, which is then added to the original. If the original starts with an amplitude of 0.5, then you'll never go outside [-1,1] no matter how many iterations you perform.
You can add or multiply sine and cosine waves, with random amplitudes, periods, and phases. Most methods involve some baseline wave and have a pattern to how the subsequent waves are combined.
For instance, you might increase the period and reduce the amplitude by a coefficient of two for the next waveform, which is then added to the original. If the original starts with an amplitude of 0.5, then you'll never go outside [-1,1] no matter how many iterations you perform.
Quote:
Original post by basszero
http://en.wikipedia.org/wiki/Perlin_noise
I used the concept to make a similar 2d-terrain looking waveform.
I've very nearly brought that up, but a PNG uses a noise function for its base function, which ideally has no sense of periodicity; while a sine wave very much does.
Although I don't know what they OP's goal is, I'll go ahead and second that as a subject of study.
Look into using noise generation. Noises can be generated with different frequencies, and Perlin's noise algorithm is a fast way to generate noise.
Different noise algorithms can produce different effects. Perlin's algorithm is somewhat band-limited, but there is a method called wavelet noise that is better at generating band-limited noise (but it is also slower). Perlin noise is good enough for a lot of purposes though.
Adding together different frequencies of noise is a sort of spectral synthesis.
Different noise algorithms can produce different effects. Perlin's algorithm is somewhat band-limited, but there is a method called wavelet noise that is better at generating band-limited noise (but it is also slower). Perlin noise is good enough for a lot of purposes though.
Adding together different frequencies of noise is a sort of spectral synthesis.
So you want a random none-repeating sinusoidal wave, that when given the y-value only returns one x-value to you?
You need a one-to-one function for that (one x-value gives out one y-value), however a standard sine wave is many-to-one function (many x values can give the same y-value).
When you try to work out the x-value, from the given y-value, you will have problems because the y-value will give multiple x-values(this is called a one-to-many function - one y-value gives multiple x-values; this is theoretically not a function.)
For a one-to-one function, basically the graph can never turn around, ie. the gradient can't go from positive to negative.

Here the horizontal line only crosses the graph once, therefore only one x-value gives one y-value => It is a one-to-one function, and has an inverse.

Here the horizontal line crosses the graph three times, therefore three x-value give the same y-value => It is a many-to-one function, and has no inverse.
A randomly generated sinusoidal wave will not have an inverse function...
----
Hope I understood you properly:
I assumed you were talking about inverses...if not, sorry to waste your time, and I hope i can answer your question, if you explain it slightly better...
Ben
You need a one-to-one function for that (one x-value gives out one y-value), however a standard sine wave is many-to-one function (many x values can give the same y-value).
When you try to work out the x-value, from the given y-value, you will have problems because the y-value will give multiple x-values(this is called a one-to-many function - one y-value gives multiple x-values; this is theoretically not a function.)
For a one-to-one function, basically the graph can never turn around, ie. the gradient can't go from positive to negative.

Here the horizontal line only crosses the graph once, therefore only one x-value gives one y-value => It is a one-to-one function, and has an inverse.

Here the horizontal line crosses the graph three times, therefore three x-value give the same y-value => It is a many-to-one function, and has no inverse.
A randomly generated sinusoidal wave will not have an inverse function...
----
Hope I understood you properly:
Quote:
I need something that is based on a value and always has the same result like this if x=1 then y=5. y always returns the same value if x=1 get it?
I assumed you were talking about inverses...if not, sorry to waste your time, and I hope i can answer your question, if you explain it slightly better...
Ben
Unless it's classified, I'd suggest you tell us a little more about what you are trying to do..
With noise generation, you can make sure you never get a 'loop'/repeating pattern, however, you'll likely get the same Y more than once (well, you have pretty much control, so you can prevent this).. sine-waves will always repeat themselves sooner or later, however, if you can put a limit on x (that is, set a max x value), then you can create a period that's greater than that max value, and never see it repeat itself.
A * sin(B * x + C) + D
A is amplitude
B is period
C moves the wave along the x-axis
D moves the wave along the y-axis
C and D doesn't modify the form/shape/whatever the mathematical term is in English, A and B does. If you set B to something smaller than 1/max_x, then you'll never see it repeating, but you might want to set it to something even smaller than that, if, that is, you still want to use sine-waves.
[edit]
My logic is a bit flawed. Assuming you are using sin() with radians, you should set B to something smaller than (2 * PI) / max_x.
With noise generation, you can make sure you never get a 'loop'/repeating pattern, however, you'll likely get the same Y more than once (well, you have pretty much control, so you can prevent this).. sine-waves will always repeat themselves sooner or later, however, if you can put a limit on x (that is, set a max x value), then you can create a period that's greater than that max value, and never see it repeat itself.
A * sin(B * x + C) + D
A is amplitude
B is period
C moves the wave along the x-axis
D moves the wave along the y-axis
C and D doesn't modify the form/shape/whatever the mathematical term is in English, A and B does. If you set B to something smaller than 1/max_x, then you'll never see it repeating, but you might want to set it to something even smaller than that, if, that is, you still want to use sine-waves.
[edit]
My logic is a bit flawed. Assuming you are using sin() with radians, you should set B to something smaller than (2 * PI) / max_x.
Quote:
Original post by DvDmanDT
A * sin(B * x + C) + D
A is amplitude
B is period
C moves the wave along the x-axis
D moves the wave along the y-axis
I just saw this in my math classes :P. I believe there are some problems with that formula of yours.
a*sin(b*(x - h)) + k
(h, k) is a point on the middle of the wave (one could call it "starting point"). Moving this point moves the wave.
|a| is the half-height of the wave (amplitude)
(2pi/b) is the period
(b/2pi) is the frequency
However I'm not sure we're really helping the OP here... shouldn't combining a few sines together with different parameters be random enough?
I'm going to use it for procedurally generating a planet were I just point a normal in some direction and get back the distance from the center but I didn't think anyone would tell me a full equation for that so I made it as simple as possible.
So you think you can fugue it out? I can't also please try to remember I'm not that good at math so make it easy or I will have to spend like 3 day trying to understand it.
So you think you can fugue it out? I can't also please try to remember I'm not that good at math so make it easy or I will have to spend like 3 day trying to understand it.
I found this page helpful. This would be the aforementioned Perlin noise generator.
Basically the idea is that you whip up a handful of pseudorandom number functions that return a consistent value from the same arguments (eg x,y,z). You go through a set of data points (like the vertexes in a heightmap) and use the first PRNG for their heights. After that, you go through again, except this time you use the next noise function, increasing the frequency and decreasing the amplitude; then you sum your results. Iterate until satisfied.
The last step is to run a smoothing function over your data, so that it looks a little nicer.
This guy also explains the interpolation of in-between points.
In general, for a spheroid object like a planet, I would suggest using an icosahedron (20 equilateral triangles).
Basically the idea is that you whip up a handful of pseudorandom number functions that return a consistent value from the same arguments (eg x,y,z). You go through a set of data points (like the vertexes in a heightmap) and use the first PRNG for their heights. After that, you go through again, except this time you use the next noise function, increasing the frequency and decreasing the amplitude; then you sum your results. Iterate until satisfied.
The last step is to run a smoothing function over your data, so that it looks a little nicer.
This guy also explains the interpolation of in-between points.
In general, for a spheroid object like a planet, I would suggest using an icosahedron (20 equilateral triangles).
Thanks to that page, the true meaning of perlin noise is now a mystery. That page does not describe perlin's noise function. It generates somewhat noisy functions and then adds them together to create a fractal. Perlin noise actually looks good even without adding together different frequencies to get the fractal effect.
Ken Perlin's homepage has some neat planet rendering demos on it, and some source code, but the code can be a bit difficult to understand.
I think that you can use a 3d noise function to determine the height of any given point on the planet. The input is the normal to that point, and the output is the height. The height is then added to the base radius of the planet to get the distance of that point from the center of the planet.
A 2d noise function would have issues with smoothly wrapping around a sphere, but I think it would work as long as the poles were scaled so that the north and south poles were smooth.
[Edited by - Vorpy on June 23, 2007 11:02:07 AM]
Ken Perlin's homepage has some neat planet rendering demos on it, and some source code, but the code can be a bit difficult to understand.
I think that you can use a 3d noise function to determine the height of any given point on the planet. The input is the normal to that point, and the output is the height. The height is then added to the base radius of the planet to get the distance of that point from the center of the planet.
A 2d noise function would have issues with smoothly wrapping around a sphere, but I think it would work as long as the poles were scaled so that the north and south poles were smooth.
[Edited by - Vorpy on June 23, 2007 11:02:07 AM]
Yeah, Unlike many web tutorials will tell you, Perlin noise is not smoothed integer noise. (a smoothed/interpolated grid of noise values) It's gradient noise, you pick random gradients (like slope but with more dimensions) and use those at the grid points.
This is a pretty good introduction to noise functions, though it doesn't tell you how to implement gradient noise:
http://libnoise.sourceforge.net/noisegen/index.html
Despite being on Simplex Noise (which is an even better alternative to Perlin noise), this paper has a pretty clear implementation of both Perlin and Simplex Noise: http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
This is a pretty good introduction to noise functions, though it doesn't tell you how to implement gradient noise:
http://libnoise.sourceforge.net/noisegen/index.html
Despite being on Simplex Noise (which is an even better alternative to Perlin noise), this paper has a pretty clear implementation of both Perlin and Simplex Noise: http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
What Vorpy describe
"I think that you can use a 3d noise function to determine the height of any given point on the planet. The input is the normal to that point, and the output is the height. The height is then added to the base radius of the planet to get the distance of that point from the center of the planet."
It's exactly what I need anyone know how?
if anyone can make a function in c++ that would be so very very... VERY!!! helpful. [grin]
"I think that you can use a 3d noise function to determine the height of any given point on the planet. The input is the normal to that point, and the output is the height. The height is then added to the base radius of the planet to get the distance of that point from the center of the planet."
It's exactly what I need anyone know how?
if anyone can make a function in c++ that would be so very very... VERY!!! helpful. [grin]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement
Can someone please show me a good math formula for this?