Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 Logarithmic interpolation?  (Read 12533 times) 0 Members and 1 Guest are viewing this topic.
matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Posted 2012-09-09 13:26:33 »

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

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Roquen

JGO Kernel

Medals: 517

 « Reply #1 - Posted 2012-09-09 14:17:53 »

What properties do you want?
Vladiedoo
 « Reply #2 - Posted 2012-09-09 15:35:52 »

I probably read your post wrong but
 1  2  3 `// 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`
 Games published by our own members! Check 'em out!
matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #3 - Posted 2012-09-09 15:51:04 »

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

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

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Roquen

JGO Kernel

Medals: 517

 « Reply #4 - Posted 2012-09-09 16:43:35 »

That's (|sin|) highly unlikely to give you what you're looking for...what do you want to do?
Vladiedoo
 « Reply #5 - Posted 2012-09-09 16:45:57 »

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.
 1 `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?
matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #6 - Posted 2012-09-09 16:49:57 »

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.

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Roquen

JGO Kernel

Medals: 517

 « Reply #7 - Posted 2012-09-09 20:34:36 »

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
matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #8 - Posted 2012-09-09 20:41:07 »

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
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.

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Roquen

JGO Kernel

Medals: 517

 « Reply #9 - Posted 2012-09-09 20:46:10 »

2) '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.
 Games published by our own members! Check 'em out!
delt0r

JGO Wizard

Medals: 143
Exp: 18 years

Computers can do that?

 « Reply #10 - Posted 2012-09-09 21:09:47 »

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

I have no special talents. I am only passionately curious.--Albert Einstein
philfrei
 « Reply #11 - Posted 2012-09-09 21:50:30 »

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.

 1  2 `       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.

music and music apps: http://adonax.com
matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #12 - Posted 2012-09-10 12:42:14 »

2) '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.
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 :/ You simply multiplicate noise(x) by n. What exactly is noise(x)? It seems to be the point where all the magic happens...

What are you really trying to do? Simplex noise done right already interpolates properly. IIRC something cubic (splines).
Yes. But simplex noise has to be done first (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.

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.

 1  2 `       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.
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?

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.
First: I will show screenshots (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?  Are you talking about the simplex noise? I didn't want to generated textures, and my "simplex noise" is 1-dimensional (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...):
• SimplexNoiseLayer
• SimplexNoise
SimplexNoiseLayer has following properties:
• length (the number of values to generate... (the length on the x axis (no y-axis present)))
• 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)
• interpolator (a class for interpolating 2 values with a given "time" factor)
SimplexNoise:
• An array/list of as much SimplexNoiseLayers to "combine".
• 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.

[size=8pt]The words written in these "-ses are words I don't really know how to describe... I'm not a native english speaker here...[/size]

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):

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
delt0r

JGO Wizard

Medals: 143
Exp: 18 years

Computers can do that?

 « Reply #13 - Posted 2012-09-10 13:42:36 »

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.

I have no special talents. I am only passionately curious.--Albert Einstein
matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #14 - Posted 2012-09-10 17:44:08 »

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

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Roquen

JGO Kernel

Medals: 517

 « Reply #15 - Posted 2012-09-10 18:04:00 »

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)
matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #16 - Posted 2012-09-10 18:47:04 »

Yay!
Awesome...

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

I think I'll go with the normal ease curve (I'll "write the implementation" (copy that function  ) too)

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Roquen

JGO Kernel

Medals: 517

 « Reply #17 - Posted 2012-09-10 19:04:48 »

You rarely need to use the more expensive version.
philfrei
 « Reply #18 - Posted 2012-09-10 23:07:43 »

Quote
What exactly is noise(x)?

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?

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:
 1  2 `         // 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.

music and music apps: http://adonax.com
Roquen

JGO Kernel

Medals: 517

 « Reply #19 - Posted 2012-09-11 06:06:17 »

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

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #20 - Posted 2012-09-11 12:35:58 »

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

Hehe... this made me laugh a bit at the end but here is a medal for sharing experience, and for giving a math lesson

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Roquen

JGO Kernel

Medals: 517

 « Reply #21 - Posted 2012-09-11 14:00:58 »

WRT: Log - SEE: Integer.numberOfLeadingZeros, which is in hardware on Intel & ARM and is an intrinsic in HotSpot (android...don't know).
matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #22 - Posted 2012-09-11 14:53:56 »

Woah... you know how beautiful this is?

EDIT: a bit shortened...
This took 1 ms for 64 elements.
-1,000000 ----------------------------------------------------------------
-0,977539 #---------------------------------------------------------------
-0,914063 ###-------------------------------------------------------------
-0,815430 ######----------------------------------------------------------
-0,687500 ##########------------------------------------------------------
-0,536133 ###############-------------------------------------------------
-0,367188 #####################-------------------------------------------
-0,186523 ###########################-------------------------------------
0,000000 ################################--------------------------------
0,186523 ######################################--------------------------
0,367188 ############################################--------------------
0,536133 ##################################################--------------
0,687500 ######################################################----------
0,815430 ###########################################################-----
0,914063 ##############################################################--
0,977539 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
1,000000 ################################################################
0,977539 ################################################################
0,914063 ##############################################################--
0,815430 ###########################################################-----
0,687500 ######################################################----------
0,536133 ##################################################--------------
0,367188 ############################################--------------------
0,186523 ######################################--------------------------
0,000000 ################################--------------------------------
-0,186523 ###########################-------------------------------------
-0,367188 #####################-------------------------------------------
-0,536133 ###############-------------------------------------------------
-0,687500 ##########------------------------------------------------------
-0,815430 ######----------------------------------------------------------
-0,914063 ###-------------------------------------------------------------
-0,977539 #---------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------
-1,000000 ----------------------------------------------------------------

This is a single layer from simplex noise with a "density" of 32.
To the left you can see the values directly and to the right it's like a progress bar, showing only "-" when -1, and only "#" when 1.

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Pages: [1]
 ignore  |  Print

 nelsongames (19 views) 2018-04-24 18:15:36 nelsongames (17 views) 2018-04-24 18:14:32 ivj94 (608 views) 2018-03-24 14:47:39 ivj94 (53 views) 2018-03-24 14:46:31 ivj94 (401 views) 2018-03-24 14:43:53 Solater (66 views) 2018-03-17 05:04:08 nelsongames (111 views) 2018-03-05 17:56:34 Gornova (176 views) 2018-03-02 22:15:33 buddyBro (747 views) 2018-02-28 16:59:18 buddyBro (94 views) 2018-02-28 16:45:17
 ByerN 12x KaiHH 12x SHC 10x NuclearPixels 10x Zemlaynin 10x Guerra2442 10x Damocles 6x VaTTeRGeR 5x orangepascal 4x philfrei 4x ndnwarrior15 3x mesterh 3x ags1 3x Phased 2x CommanderKeith 2x delt0r 2x
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org