Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / simple curve - need to reverse it

Author
Message
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 23rd Apr 2013 01:47
I use this simple decelleration function quite a lot and it's been really useful.
However, I need to reverse the curve to an acceleration curve and have had several attempts at what I thought should be a simple bit of maths.

The following code produces the graph in fig 2, by repeatedly passing the destination and source values into the function.



I want to adapt this to produce the curve in fig 1.

No, I don't want to use hermites or beziers here, as this is a very simple recursive curve, not a relational or time bound curve.

it should be simple, but I can't seem to figure it out.

Attachments

Login to view attachments
Jimmanator
14
Years of Service
User Offline
Joined: 12th Nov 2010
Location:
Posted: 23rd Apr 2013 02:52
Do you Mean Like This:
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 23rd Apr 2013 20:24
That kind of works, but doesn't ease at the same rate.

This is yours going from 0 to 10 with a speed of 132


and this is the original going from 0 to 10. See the smooth curve towards 10



Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 24th Apr 2013 21:09
I can't speak mathematically, but code-logically shouldn't it be something like

Interval increases with distance rather than decreasing as in the original
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 24th Apr 2013 22:20
Hi Marl,
I can tell that isn't going to work as destval# isn't even referenced. Also my example with sourceval# as 0 wouldn't change anything.

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 25th Apr 2013 01:28
Yeah, I think you need another parameter to represent the start point.

The original function is based on the distance remaining, so I think it's inverse should be based on the distance traveled.

Because you are moving SourceVal#, it's clouding the logic and effectively removing the history of the function.

But, like I said before, I tend to think in programming terms and so it may not hold up to mathematical scrutiny
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 25th Apr 2013 01:34
I've had several goes at this and can't work it out. On first look, it should be easy!
However, it's not is it?

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 25th Apr 2013 17:17
Maybe this will help:
Your figure 1 looks like an exponential function something like
2^x
Whereas your figure 2 looks logarithmic (i.e. ln(x)) or something even like -1/(2^x).

I can't remember how to specifically shape exponential and logarithmic functions nor can I seem to find it on the internet.

Can you give a more solid definition of your function with what variables are constants, what the constant values are, and what your input variable range is?

Also you might want to try tinkering with something like this:
https://www.desmos.com/calculator

I do wish I could find a program that essentially lets me pick what kind of curve I want and then input minimums, maximums, and crossing points. It'd be really nice to draw a curve and get an equation! You may also want to try some equation fitting tool like what is built in to Excel or Open Office Calc. But they're not the best at fitting exponential equations.

www.NaplandGames.com
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 25th Apr 2013 22:02
Hi,

The function is self feeding like this:



So, you can see the sequence in the earlier post, where test# smoothly arrives at 10.0 from 0.0 (or near enough), with a larger value of speed# slowing the transition.

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 25th Apr 2013 22:25 Edited at: 25th Apr 2013 22:57
Got it. So the inversion isn't all that tough, but getting the perfect results may be.

Basically your function (in the mathematical sense) is:
y = [x*(S - 1) + B]/S
Where x = SourceVal#
B = DestVal#
and S = Speed#

To invert the function just solve the equation for x
which yields
[S*y - B]/[S-1]
And then make y be your input for SourceVal#

The problem you'll see is picking a start point for the sourceVal#
If you pick 10 (the limit) you'll always get 10
So you have to figure out how many iterations you want to go through before calling it quits. Then using something like Excel enter 9.9999 and fiddle with the decimal until you get the appropriate curve (i.e. the speed of the curve, really).

I hope this helps!

EDIT
Actually if you're looking for something that starts at 0 then this isn't quite it. Sorry.
It would be more like
[S*y + B]/[S-1]
But the acceleration of that is quite rapid and hits 10 after only 92 iterations whereas the original function hits 9.99 after 910 iterations.

Ick... this isn't so simple

I don't have enough time to toy with it more, but I hope this at least sets you on the right path. There's something I'm not remembering.

www.NaplandGames.com
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 25th Apr 2013 23:46
This is why it's so annoying. I thought this would be so simple too!

Firstly, I'm not after full accuracy, as I'd interrupt the curve if it was low enough anyway. 0.0 and 10.0 are just arbitrary start and end values - could be anything.

In a real world scenario, I'd stop using the function when it was 80% to target and use a different model from there.

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 26th Apr 2013 00:03
Well, that inverse function should do it for you then, you just need to add another coefficient in there somewhere to reduce the acceleration. Maybe taking a fraction of Y would do it.
Toss it into a speadsheet and play around, you'll get it.

www.NaplandGames.com
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th Apr 2013 00:20
A proper curve value function should work whether you're accelerating or decelerating. Like this one:

Watch the line grows very quickly at first, then gradually grows slower and slower. Same thing happens if you reverse the number, set s# to 1 and change the 1 to a 0 in the function call and the line will shrink, quickly at first then begin shrinking more slowly the smaller it gets. That is what you want isn't it?


"You're all wrong. You're all idiots." ~Fluffy Rabbit
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 26th Apr 2013 01:02
Phaelex: That's exactly what I have now.

The problem is changing it so the slow part is at the beginning, with gradual acceleration towards the target

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th Apr 2013 08:54
Oooo ok, I gotcha now, misunderstood. So you just want acceleration.


Would this help?


"You're all wrong. You're all idiots." ~Fluffy Rabbit
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 26th Apr 2013 20:40
Phaelex: I can do acceleration like that.
However, the issue was about altering the original function to give the opposite curve - as per the curve in the first post.

That way, the start and end of the acceleration are bound with min and max values as well, plus it's somewhat more elegant.

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 26th Apr 2013 21:26
I don't think there is a simple solution to this. By feeding the result back into the equation you've essentially created a logarithmic function, but it gets more complex to solve with every iteration.

I'd go see if someone on a calculus forum can help you out. Or maybe they can suggest a different way of writing your original equation. I'd honestly write the original equation as a polynomial, then you can more easily control it's intercept and maxima. Plus you can invert it a bit easier.

Anyway, here's a spreadsheet with the equation and its inverse. You can tap in coefficients until you get your desired results.

www.NaplandGames.com

Attachments

Login to view attachments
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 26th Apr 2013 21:43
In a way, I'm kinda glad it's not straightforward. I thought I had gone stupid overnight when I couldn't work it out.

Feeding the value back in works just fine for decceleration.

I'll probably redo the original method as you say, but consider it working in acceleration mode as well this time.

Thanks for the help.

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 26th Apr 2013 21:45
I thought I went stupid too when the original inverse didn't simply work... flawed logic will get ya every time!

Let us know how you make out.

www.NaplandGames.com

Login to post a reply

Server time is: 2024-11-24 11:56:27
Your offset time is: 2024-11-24 11:56:27