Skip to content
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

Merged
merged 4 commits into from
Oct 1, 2014
Merged

Added sinh function to FlxMath #1309

merged 4 commits into from
Oct 1, 2014

Conversation

SeiferTim
Copy link
Member

Might be nice to add others...

@Gama11
Copy link
Member

Gama11 commented Sep 30, 2014

Use cases?

@SeiferTim
Copy link
Member Author

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

@SeiferTim
Copy link
Member Author

I don't know much about how to do much actual Haxe code: http://api.haxe.org//cs/system/Math.html#Sinh

@gamedevsam
Copy link
Contributor

This seems like a fine edition, I would like to see link on the function comment that explains how this function might be used.

@MSGhero
Copy link
Member

MSGhero commented Sep 30, 2014

Might as well add the other ones too. http://en.wikipedia.org/wiki/Hyperbolic_function

@gamedevsam
Copy link
Contributor

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.

@SeiferTim
Copy link
Member Author

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;
};
Copy link
Member

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?

Copy link
Member Author

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.
@Gama11
Copy link
Member

Gama11 commented Sep 30, 2014

It probably makes sense to add tanh and cosh as well just for consistency? The others probably don't have a lot of use cases?

/**
* Hyperbolic sine.
*/
public static inline function sinH(f:Float):Float
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

@SeiferTim
Copy link
Member Author

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

@gamedevsam
Copy link
Contributor

I recommend we don't add any functions that we can't test and verify they work correctly.

@SeiferTim
Copy link
Member Author

@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.
Basically, I had to look up what sinh was and got that it was (x^2 - -x^2) / 2 and turned that into code.
I didn't look at the other ones yet, but they are apparently all here: http://math2.org/math/trig/hyperbolics.htm (and easier to understand than:
-i * sin(i * x)

@gamedevsam
Copy link
Contributor

I know you tested sinh(), my comment was for additional functions.

@Gama11
Copy link
Member

Gama11 commented Sep 30, 2014

Speaking of test, a unit test for this would be nice. ;)

@MSGhero
Copy link
Member

MSGhero commented Sep 30, 2014

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.

@SeiferTim
Copy link
Member Author

@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?)

@sruloart
Copy link
Contributor

A user case: A crazy man decides to build a math game, and he doesn't know math.

@MSGhero
Copy link
Member

MSGhero commented Sep 30, 2014

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

@sruloart
Copy link
Contributor

tanh is used to add velocities when relativity starts to matter...

Finally, a setup for a proper physics system.

@Gama11 Gama11 changed the title Added sinH function to FlxMath Added sinh function to FlxMath Oct 1, 2014
Gama11 added a commit that referenced this pull request Oct 1, 2014
Added sinh function to FlxMath
@Gama11 Gama11 merged commit c3db40a into HaxeFlixel:dev Oct 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants