I just need a function that would graph out like this:
In case my graph isn't clear, the line switches from negative to positive at exactly 1/3. Does anyone know how to express that in math terms?
My old nemesis, math
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
My old nemesis, math
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: My old nemesis, math
I've learned to never do coding math at 1:45 am. So many hours wasted that way. We should probably go to bed
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: My old nemesis, math
Thanks, /mum/. Anyone else have an answer?
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: My old nemesis, math
Is that the only requirement you have? Because TechnoCat's suggestion fulfils that requirement, but doesn't look much like your graph otherwise.Taehl wrote:In case my graph isn't clear, the line switches from negative to positive at exactly 1/3.
Help us help you: attach a .love.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: My old nemesis, math
I'd suggest asking the same question on http://math.stackexchange.com/ . Those guys are really good at math (and they answer really fast)
When I write def I mean function.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: My old nemesis, math
No, it also needs to range from just -.1 to +.1, not from -infinity to +infinity.Robin wrote:Is that the only requirement you have? Because TechnoCat's suggestion fulfils that requirement, but doesn't look much like your graph otherwise.Taehl wrote:In case my graph isn't clear, the line switches from negative to positive at exactly 1/3.
Currently I'm kind of cheating around it by going (math.clamp(-1/3, .01/(n-1/3), 1/3))%1, but having the proper function would be better.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: My old nemesis, math
Maybe something likeTaehl wrote:I just need a function that would graph out like this [...] the line switches from negative to positive at exactly 1/3. Does anyone know how to express that in math terms?
Code: Select all
(2-2*math.atan(x-1/3)/math.pi)%2-1
You can also use other sigmoid instead of math.atan, might be faster - http://en.wikipedia.org/wiki/Sigmoid_function - for example with x/(1+|x|):
Code: Select all
(2-(x-1/3)/(1+math.abs(x-1/3)))%2-1
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: My old nemesis, math
Thank you for the resource, kikito. I quickly got an answer that seems correct. Now I just have to figure out, how the heck do I make this crazy "arccotangent" thing in Lua???
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: My old nemesis, math
iirc in lua you only get atan, not acot - that's why I made you one with it instead of acot Anyway, for sake of game - I'd say avoid trigonometric functions in not necessary, they are heavy to compute. You get similar looking result with any sigmoid function, and if you use one that is simple like proposed above, you get result a lot faster.Taehl wrote:Thank you for the resource, kikito. I quickly got an answer that seems correct. Now I just have to figure out, how the heck do I make this crazy "arccotangent" thing in Lua???
If you like Wolframs previews - the one based on absolute value looks quite similar and you avoid calculating complex expressions under the hood.
Who is online
Users browsing this forum: No registered users and 5 guests