# Find nearest maximum to random location on 1D perlin noise function

This topic is 2139 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is it possible to find (approximate) nearest maximum of Perlin noise function for specific random value?

I draw this sketch to illustrate:

If red dot represents random offset on the Perlin noise function, is it possible to approximate where the nearest maximum is?

I would like for animation to always start at the top of the wave (so it always drops first).

##### Share on other sites

If you calculate the derivative of the noise function you obtain a gradient value that indicates which way the function is going at X. That is, if the function is increasing at X, then the gradient will be positive, whereas if the function is decreasing the gradient will be negative. Local maxima/minima are places where the gradient is equal to 0. At those places, the function is neither increasing nor decreasing. So you can calculate the derivative at X, then iteratively "move" in the direction indicated by this gradient value (decrease X for negative gradient, increase X for positive) until the gradient approaches near enough to 0 to be considered "close enough". That should be your nearest maximum.

##### Share on other sites

I think the Perlin noise function works on gradients anyway.

There is a local minima/maxima inbetween sample points if the sign of the derivative changes between sample points (since it is continuous).

##### Share on other sites

Thank you! That would work. I have implemented Perlin noise function that calculates derivative, from Gustavson's code. Then I realized the real cause of the problem was not the starting point on Perlin's function, but a bug in my code that caused that attenuation of magnitude (of my effect) was dependent on random offset on Perlin's function. I fixed it and now animation behaves as expected.

• 18
• 29
• 11
• 23
• 16