Maths help!

Soldato
Joined
18 Oct 2002
Posts
15,177
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:

tyre-graph.jpg


*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:
Associate
Joined
14 May 2010
Posts
1,136
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:
Soldato
OP
Joined
18 Oct 2002
Posts
15,177
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:

polynomial.jpg


Thanks again, beer and cookies are on me!

36356.jpg


Decadent-Chocolate-Chip-Cookies.jpg
 
Soldato
OP
Joined
18 Oct 2002
Posts
15,177
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:
0.000000002291032891 * x^10 - 0.00000030551481 * x^9 + 0.00001742387542 * x^8 - 0.0005544179378 * x^7 + 0.01076963547 * x^6 - 0.1313698186 * x^5 + 0.9973748349 * x^4 - 4.492224546 * x^3 + 10.50060047 * x^2 - 7.513197218 * x + 2.121501817

Which becomes this:
fixed-polynomial.jpg


Hurrah!
 
Soldato
Joined
28 Oct 2006
Posts
12,456
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:
Soldato
Joined
25 Nov 2002
Posts
3,495
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
 
Back
Top Bottom