# Maths help!

Discussion in 'HTML, Graphics & Programming' started by GravyMonster, 6 Jun 2012.

1. GravyMonster

# Location: The land of milk & beans

Hey all,

I'm trying to make a racing driver management sim and I've got the basics working in a C# console app. You give the code a track, driver and a car and it'll spit out X number of laptimes.

Now, I'm trying to model tyre degredation in to the laptimes and I know how I want to do it, unfortunately my GCSE maths is letting me down. What I need is to get values in the range 0-10 for the grip level based on the current lap and the tyres being used. Here's a basic graph I knocked up in PS to demonstrate the model:

*edit*
Just realised I forgot the key - Soft, Medium, Hard

Now from my research I think I need to use the trigonometry functions of Math, however I don't understand what/how to make them work for this scenario?

Virtual cookies/beers are on offer for anyone can give me a nudge, link, or example code showing how I can do this

Thanks guys.

Last edited: 6 Jun 2012
2. ZombieFan

# Location: Somerset

I'm no expert on this, but you simply(!) have to find the equation which matches the graphs as near as possible. There are quite a few equation-to-graph converters on the web - http://www.meta-calculator.com/online/ seems to work well.

I've had a quick play and come up with...

y = sin((x - 6) / 4) * 4.5 + 5.5

...which gives you a pretty good sine wave which fits your co-ordinates. If you can work out how to skew the graph to the left or right then you should be able to match it up to your graphs pretty well.

Then just use this equation in your code and your all sorted!

Last edited: 6 Jun 2012
3. GravyMonster

# Location: The land of milk & beans

Thanks for the help!

I managed to solve this using Excel in the end - shock, horror! The graphing tool has a handy feature which lets you create a polynomial trend line from a dataset, and it will also generate the equation for the curve for you too. I ended up with this:

Thanks again, beer and cookies are on me!

4. GaryH-21

# Posts: 470

oh yeah, simple stuff that.....

:|

5. GravyMonster

# Location: The land of milk & beans

Hmmm it appears I spoke too soon. The equation excel spits out only maps the first part of the curve... is that all that's possible with one equation?

Original:

And then that equation plotted:

6. marc_howarth

# Location: Matlock

The curves looks somewhat like an exp(-t^2) function

Maybe something like this would work?

7. GaryH-21

# Posts: 470

I think the problem has something to do with BODMAS.....

8. GravyMonster

# Location: The land of milk & beans

Thanks, that looks bang on, what kind of curve/equation is that? Do you have any examples of how to calculate it from a set of figures?

9. GravyMonster

# Location: The land of milk & beans

Aha! I think I've cracked it, thanks mostly to this online too, which spits out polynomial equations based on supplied x,y coords.

That gave me this:
Which becomes this:

Hurrah!

10. touch

# Location: Sufferlandria

That looks like quite a complex function. It might be more efficient to just store the grip values in a lookup table?

edit: actually, i misread the OP. I thought it was a racing game rather than a racing management game. Maybe the efficiency of the calculation is not that important.

Last edited: 8 Jun 2012
11. GravyMonster

# Location: The land of milk & beans

That was my plan B. I may still do it that way, depending on how the modelling of the other tyre compounds goes.

12. Mr^B

# Posts: 3,436

I'd ditch the equations and go with the suggested lookup table.

It has a number of advantages;

1. No strange formulas in the code
2. Probably quicker
3. Easier to tweak