Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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 3448 times)
0 Members and 1 Guest are viewing this topic.
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Posted 2012-09-09 15: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 Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Roquen
« Reply #1 - Posted 2012-09-09 16:17:53 »

What properties do you want?
Offline Vladiedoo
« Reply #2 - Posted 2012-09-09 17: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!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #3 - Posted 2012-09-09 17: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 Smiley

(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
Offline Roquen
« Reply #4 - Posted 2012-09-09 18:43:35 »

That's (|sin|) highly unlikely to give you what you're looking for...what do you want to do?
Offline Vladiedoo
« Reply #5 - Posted 2012-09-09 18: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?
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #6 - Posted 2012-09-09 18: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
Offline Roquen
« Reply #7 - Posted 2012-09-09 22: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
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #8 - Posted 2012-09-09 22: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 Smiley
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
Offline Roquen
« Reply #9 - Posted 2012-09-09 22: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!
Legends of Yore - The Casual Retro Roguelike
Offline delt0r

JGO Knight


Medals: 26
Exp: 18 years


Computers can do that?


« Reply #10 - Posted 2012-09-09 23: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
Offline philfrei
« Reply #11 - Posted 2012-09-09 23: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.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #12 - Posted 2012-09-10 14: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 Smiley (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 Smiley (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 Smiley (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
Offline delt0r

JGO Knight


Medals: 26
Exp: 18 years


Computers can do that?


« Reply #13 - Posted 2012-09-10 15: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
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #14 - Posted 2012-09-10 19: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 Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Roquen
« Reply #15 - Posted 2012-09-10 20: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)
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


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

Yay!
Awesome...

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

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

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Roquen
« Reply #17 - Posted 2012-09-10 21:04:48 »

You rarely need to use the more expensive version.
Offline philfrei
« Reply #18 - Posted 2012-09-11 01: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.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline Roquen
« Reply #19 - Posted 2012-09-11 08: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.
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


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

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

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

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Roquen
« Reply #21 - Posted 2012-09-11 16:00:58 »

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

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


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

Woah... you know how beautiful this is? Smiley

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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (13 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!