Logarithmic interpolation?

EDIT: Old topic: “Periodic function with the frequence at each point given from another function”. See below for the new question.

Hey guys. (There should be something like a “mathematical questions” subforum…)

I want to have a function looking like a f(x)=-|sin(x)|+1 function, but the offset between two “1”-value points should be variable and defined by another noise function. How can I do this?

I hope I gave you enough information… If not, please ask for it :slight_smile:

What properties do you want?

I probably read your post wrong but


// as variance gets smaller the space between each 1 value gets larger
// as variance gets larger the space between each 1 value gets lower
-Math.abs(Math.sin(variance * x))+1

Yes… that is very good… So now I only have to iterate through all my values, changing variance to the value from the noise… of course!

God… The answers are always so simple… and I almost thought about implementing my own sin hehe… dumb me

Now thank you :slight_smile:

(I also have a second problem: how do I interpolate 2 values (for example 10 and 50 with distance 100) logarithmic?)

That’s (|sin|) highly unlikely to give you what you’re looking for…what do you want to do?

Delayed response but this is the second equation you asked for, I used https://www.desmos.com/calculator to create the graph so I’m sure there is a better way to do it.

Math.abs(Math.sin(.032x))+45*Math.abs(Math.sin(.016x))+5

Like Roquen said though, it’d be better if we knew what you’re trying to accomplish, are you trying to create background mountains?

No, not backgrounds… it’s harder. For backgrounds I’d simply use my 1D Value Noise or my 1D simplex noise…

I want to Populate a 1D surface with trees. For that I use a periodic funciton (the sinus function with these spikes), which I want to change a bit, so the trees have a bigger density at some points than on others.

The final function (actually float-array) holds the possiblities for the trees to spawn.

The periodic function ensures that trees don’t spawn too near to each other, and the noise makes everything have some life, so it’s not like every tree is directly next to each other.

Quick thoughts off the top of my head:

  1. low frequency noise time high frequency noise.
  2. r = n*noise; r = r - (int)r
  3. combo of the previous

About the stuff with these periodic functions with frequencies defined by simplex noise: I’ve got that working…

What I want to do now: I want to “improve” my simplex noise interpolation algorithm with quadratic in-out-easing curves. They look like logarithmic growth… But I think the curve for logarithmic interpolation is different… can anybody help me?

@Roquen: Sorry… I did not understand that one :slight_smile:

  1. understood
  2. erm? r, n and noise = what? or better: what exactly?
  3. hmm. I think I have to understand 2 first for that one.
  1. ‘n’ is some constant. you calculate r= n*noise(x), the result is r = r - (int)r. classic example this is used to create wood grains.

What are you really trying to do? Simplex noise done right already interpolates properly. IIRC something cubic (splines).

I just tried using the Math.log1p(x) function with the inputs 0 and 1.
It gives an output that ranges from 0 to 0.6931471805599453.

So one could get an output range from 0 to 1 by multiplying by the inverse: 1.4426950408889634

I assume you can normalize the distance between the two points you wish to interpolate.

   
    double A = Math.log1p(x) * 1.4426950408889634;

Then, you can multiply your two values by A and 1-A.

Does this work? Math is NOT my forte.

P.S. Am VERY interested to see what you are coming up with using textures & noise!! I hope you will post some graphics at some point.

Sorry… Seems to be something which could be helpful, (if you say that It’s an classic example? yeah… I think so) but I didn’t understand it yet :confused: You simply multiplicate noise(x) by n. What exactly is noise(x)? It seems to be the point where all the magic happens…

Yes. But simplex noise has to be done first :slight_smile: (I’ve tried out hermetic spline curves (I somehow didn’t got that working properly…) and cubic splines are the next ones I want to test.

Erm… intresting… I’ve never heard about log1p… what curve does it give, if I feed x values ranging from 0 to 1 to the function? You say they range from 0 to 0.693, but in which way?

First: I will show screenshots :slight_smile: (They won’t be special… only some trees on a 2D planet… (side scrolling view)) or maybe I’ll post a curve graph from what it generates…

Second: textures? :persecutioncomplex: Are you talking about the simplex noise? I didn’t want to generated textures, and my “simplex noise” is 1-dimensional :slight_smile: (propably the name is anothe one…). But the simplex noise is constructed like simplex noise is constructed usually… I think…

My “algorithm” consists of 2 data structures (? Should I call them like that? they are 2 classes…):
[x] SimplexNoiseLayer
[x] SimplexNoise

SimplexNoiseLayer has following properties:
[x] length (the number of values to generate… (the length on the x axis (no y-axis present)))
[x] density (hard to explain… for example if density is 4, then every 4th value in the array will be set to randomly either -1 or 1)
[x] interpolator (a class for interpolating 2 values with a given “time” factor)

SimplexNoise:
[x] An array/list of as much SimplexNoiseLayers to “combine”.
[x] An array of “importances” for each layer.

The the importance for each layer gives informaiton about how strong it will affect the values for the “final” array.

Everything is 1-Dimensional.

The words written in these "-ses are words I don’t really know how to describe… I’m not a native english speaker here…

The only problem for me right now is the simplex noise interpolator… The other stuff works… the interpolator should give something wich looks somehow like this (from google):
http://www.helixtech.com.au/Images/Delta-T6_Dyn_Vel_HermiteSpline.jpg

Hermetic spline curves are unique. In order to enforce the simplex noise continuity condition you will always end up with hermetic spline cubic curves. They are also the easiest out of the splines not requiring solving systems of equations. In fact I think the original simplex paper even has a nice way of interpolating with bases functions which make it even easier over the simplex grid. Certinally faster.

hmmm… I just found the cubic spline curve function: 3x² - 2x³ which just looks awesome right now. If I put on some scaling onto that function (the critical part is x=0 to x=1), then this could give me just the interpolation I want :slight_smile:

noise(x) = your simplex noise
3x² - 2x³ = what Perlin originally used as an “easy” or “S-curve” weighting function (first-order continuous)
later changed to, the more expensive: t * t * t * (t * (t * 6.f - 15.f) + 10.f)

Yay!
Awesome…

https://www.desmos.com/calculator/0ytgghltgc

I think I’ll go with the normal ease curve :slight_smile: (I’ll “write the implementation” (copy that function ;D ) too)

You rarely need to use the more expensive version.

[quote]What exactly is noise(x)?
[/quote]
I’ve been wondering the same thing. As far as I can tell, the range noise(0) to noise(1) is going to have the same general degree of randomness as the range noise(100) to noise(101)–just translated to a different set of points on the noise field. How one relates those differences to a width of a graphic on the screen or to a given number of pixels depends on the scaling function used.

So if a graphic has width W, any you use (x / W) as the argument to the noise function (where x is some value between 0 and W), you will be feeding the values that range from 0 to 1 to the noise function. Thus two graphics of different widths will have results where the texture looks scaled when comparing them.

There is undoubtedly an absolute number N that represents the “period” of the noise, inasmuch as a random function can have a period. But I don’t know what that is yet, and it is probably different for ImprovedNoise vs Simplex noise. Surely it is related to the spacing of the random gradients.

[quote]I’ve never heard about log1p… what curve does it give, if I feed x values ranging from 0 to 1 to the function? You say they range from 0 to 0.693, but in which way?
[/quote]
The function is f(x) = ln(x+1), which is the inverse of f(x) = e^(x+1).
Math.log1p(0) = 1, Math.log1p(1) = 0.693.

http://docs.oracle.com/javase/7/docs/api/index.html

I came across it when trying to come up with a natural growth distribution for the brightness of the stars in my “procedural night sky”. The function returns the natural log of a given number + 1. Since ln(0) is infinity, this is a bit more convenient to use than the Math.log() function. Note also that ln(1) = 0. (Any number, including e, to the 0th power = 1.)

I wanted dim or small stars to be more likely to occur than bright stars, and I wanted the distribution to reflect exponential growth. I came up with this bit of code to accomplish this:

			// choose size (five sizes possible)
			int size = 4 - (int)Math.log1p(random.nextInt(148));

This is based on the fact that 148 = (roughly) e^5. By using the Math.log1p() version, I didn’t have to eliminate 0 as an output of the random.nextInt() function.

But it seems you were after something different and you found it.

A given implementation of one of these noise functions will have a period (or not) by design…by wrapping the cells or not.