-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added sinh function to FlxMath #1309
Conversation
Might be nice to add others...
Oops...
Use cases? |
I needed it for some Procedural-generation stuff. It looks like the function exists in Haxe, I just couldn't figure out how to access it, so I added it to FlxMath... |
I don't know much about how to do much actual Haxe code: http://api.haxe.org//cs/system/Math.html#Sinh |
This seems like a fine edition, I would like to see link on the function comment that explains how this function might be used. |
Might as well add the other ones too. http://en.wikipedia.org/wiki/Hyperbolic_function |
The Wikipedia article is super technical, I was hoping for a more user friendly resource, that shows the use of the function within the context of game development. |
I'm using it to make a randomized number of items increase over time but never quite hit a maximum. |
public static inline function sinH(f:Float):Float | ||
{ | ||
return (Math.exp(f) - Math.exp(-f)) / 2; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's with the ;
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Nothing to see here... ;)
Removed unnecessary semicolon.
It probably makes sense to add |
/** | ||
* Hyperbolic sine. | ||
*/ | ||
public static inline function sinH(f:Float):Float |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The h
doesn't seem to be capizalized generally.
- http://msdn.microsoft.com/en-us/library/system.math.sinh(v=vs.110).aspx
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh
- http://www.tutorialspoint.com/java/lang/math_sinh.htm
Let's stick to that convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
I didn't add the other ones only because I didn't know how to code them - I found this one from a math website and tweaked it so it would work. I can try to add some others, although, I'm not good at math and I haven't see them lol |
I recommend we don't add any functions that we can't test and verify they work correctly. |
@gamedevsam It definately works, I had a spreadsheet setup that was using a sinh function, and after putting it into my code and running it, my numbers matched what the spreadsheet had. |
I know you tested |
Speaking of test, a unit test for this would be nice. ;) |
I linked the Wikipedia for the other functions and little tricks, like even and odd functions, to simplify the math a bit possibly. I have no idea what the use cases are for these. |
@MSGhero yeah, I'm using it for procedural-generation stuff. That's where I imagine most of the uses would come from. I could see maybe using them for motion or something, too, but not too much else. (But what do I know?) |
A user case: A crazy man decides to build a math game, and he doesn't know math. |
Did a bit of digging: the only use of cosh that could apply to a flixel game would be a dangling rope with 2 fixed ends which makes a cosh graph. I'm not against adding them in, especially if they do procgen which I didn't see anything for. tanh is used to add velocities when relativity starts to matter... |
Finally, a setup for a proper physics system. |
Might be nice to add others...