View Full Version : Question/request about speed
J@tko
16th January 2008, 19:32
Hi programmers.
I'm looking for a little insim programme for the upcoming Kyoto 250 and 500.
I'd like lap times displayed as a speed rather than a lap time, as it makes it more realistic. Can you program insim to take each lap time, then divide 1.9 (oval length) by the lap time, then multiply it by 3600 to give the lap in mph?
Is this easy to do/impossible or what?
If it's not too much, would someone do this for me? I'd be glad to give credit on the credits and you could also release it to the community as a useful tool.
Thanks
J@tko
mcgas001
16th January 2008, 19:33
Sounds easy to program but the maths to get the MPH in speed is what freaks me out.
J@tko
16th January 2008, 19:35
Sounds easy to program but the maths to get the MPH in speed is what freaks me out.
Speed = distance / time
Here we have the distance in miles, and the speed in seconds, e.g 1.9 miles in 41 secs. 1.9/41 = 0.046341463 miles per second. There are 3600 seconds in an hour, so we times by this to get the speed in mph - 166.82 mph.
Now i've done the maths - you do the insim :razz:
mcgas001
16th January 2008, 19:36
LOL, give me a little while ill see what i can snap together :)
J@tko
16th January 2008, 19:37
LOL, give me a little while ill see what i can snap together :)
Cheers :thumb: (and please add it to the server whilst your at it :D)
What's the server called and is it online all the time?
DarkTimes
16th January 2008, 19:53
I actually recently added this functionality to the in development version of LFSPoints. I took the track lengths from here (http://en.lfsmanual.net/wiki/Tracks), and used this simple algorithm:
double avgSpeed = (trackLength / (lapTotalMilliseconds / 1000)) * 3600;
I've not had time to check it to make sure it's exactly right, but it seems to work well enough. I've no idea when LFSPoints V2.3 Final will be released though, it's a bit of a mess right now and I don't have the energy to finish it.
mcgas001
16th January 2008, 20:03
I actually recently added this functionality to the in development version of LFSPoints. I took the track lengths from here (http://en.lfsmanual.net/wiki/Tracks), and used this simple algorithm:
double aveMph = (trackLength / (lapTotalMilliseconds / 1000)) * 3600;
I've not had time to check it to make sure it's exactly right, but it seems to work well enough. I've no idea when LFSPoints V2.3 Final will be released though, it's a bit of a mess right now and I don't have the energy to finish it.
Heh works well, This program is almost done already :D
J@tko
16th January 2008, 20:06
...
I'm asking Victor if he has any 'more exact' lengths for the oval, as it currently says 1.9 miles, but that could be anywhere between 1.85 miles (gives 161 mph on a 41 sec lap) and 1.94 (gives 171 mph on a 41 sec lap)
BTW, thanks for the LFS Points, I'm using it for the LFS BC. Perfect lazy man's tool :thumb:
mcgas001
16th January 2008, 20:07
I'm asking Victor if he has any 'more exact' lengths for the oval, as it currently says 1.9 miles, but that could be anywhere between 1.85 miles (gives 161 mph on a 41 sec lap) and 1.94 (gives 171 mph on a 41 sec lap)
BTW, thanks for the LFS Points, I'm using it for the LFS BC. Perfect lazy man's tool :thumb:
I could get that myself?, All i gotta do is check between every X,Y save it up for a lap, then Convert it too miles at the end?
J@tko
16th January 2008, 20:10
I could get that myself?, All i gotta do is check between every X,Y save it up for a lap, then Convert it too miles at the end?
I presume your talking some insim talk I don't understand. :razz:
If so - then do it. The more accurate the better.
Even better, could you calculate how far the car travels in the lap to get it really accurate?
Or is that not possible?
/me is a programming noob :)
mcgas001
16th January 2008, 20:11
Yep, i could make it save the distance from 1 lap to the next, then give a lap time based on that, if you wish?
J@tko
16th January 2008, 20:14
Yep, i could make it save the distance from 1 lap to the next, then give a lap time based on that, if you wish?
How accurate would that be? yard? inch? (insert whatever's below an inch!)
If so, then go for it!
The more accurate the better!
mcgas001
16th January 2008, 20:20
Im not sure what the insim X,Y is by default, but i would work it out in meters, the convert it to miles...if that helps
ill make a test and see what the results are...
J@tko
16th January 2008, 20:21
Im not sure what the insim X,Y is by default, but i would work it out in meters, the convert it to miles...if that helps
ill make a test and see what the results are...
Thanks :thumb:
dougie-lampkin
16th January 2008, 20:34
But wouldn't it depend on the driver's line into the corners?
J@tko
16th January 2008, 20:39
But wouldn't it depend on the driver's line into the corners?
Yes, that's why I wanted it to work out the distance travelled on each lap.
dougie-lampkin
16th January 2008, 20:42
Yes, that's why I wanted it to work out the distance travelled on each lap.
But the distance travelled depends on the line doesn't it? If you drive along the inside, you will do maybe 400 metres less than a driver on the outside of the track...which would affect speed by 5-10mph i suppose...
J@tko
16th January 2008, 20:47
But the distance travelled depends on the line doesn't it? If you drive along the inside, you will do maybe 400 metres less than a driver on the outside of the track...which would affect speed by 5-10mph i suppose...
I mean like for the insim to work out the distance car x travelled between crossing the line for the start of one lap and the start of the next one.
dougie-lampkin
16th January 2008, 20:48
Ah, sorry, I though you were trying to work out what the length of the track was, and using that...ignore my posts then :shy:
J@tko
16th January 2008, 20:50
Ah, sorry, I though you were trying to work out what the length of the track was, and using that...ignore my posts then :shy:
NP. That was my original thought, but then I thought what you thought, and my I thought that my original thought was not as good as the thought I subsequently came up with that happenned to be the same as your thought.
I think.
dougie-lampkin
16th January 2008, 20:51
NP. That was my original thought, but then I thought what you thought, and my I thought that my original thought was not as good as the thought I subsequently came up with that happenned to be the same as your thought.
I think.
Proves I'm 5 minutes slower than the rest of the population...:D
DarkTimes
16th January 2008, 21:20
Well I'd imagine that the actual distance a car travels will not differ too much between different drivers, probably not more than a few meters per lap, which is pretty trivial. I'd take a guess that in 'proper' oval racing they do not messure the exact distance a car travels when working out the speed, but just have the length of the track as a constant.
Edit: Incidentally, I'd be extremely grateful if someone could provide me with more accurate track lengths. :)
J@tko
16th January 2008, 21:31
Edit: Incidentally, I'd be extremely grateful if someone could provide me with more accurate track lengths. :)
I asked Victor here (http://www.lfsforum.net/showthread.php?p=677968#post677968) what the length of the Oval was. See what he says back.
DarkTimes
16th January 2008, 21:34
OK cool. The idea of doing a lap on the speed-limiter is quite clever, but I don't want to do that for every combo... Ooh, that idea makes my head hurt...
mcgas001
16th January 2008, 21:38
OK cool. The idea of doing a lap on the speed-limiter is quite clever, but I don't want to do that for every combo... Ooh, that idea makes my head hurt...
DarkTimes, have a break. you helped me before, ill try get you Excat distances for every track :)
duke_toaster
16th January 2008, 21:42
NASCAR measure the length of a track 15 feet from the outside wall (for ovals), the FIA do it as in the middle unless a track is really long.
NASCAR source (http://www.jayski.com/pages/faqrace.htm#track-measure), the F1 bit is in Appendix O but I'm not sure where :p
DarkTimes
16th January 2008, 21:55
Interesting thanks!
If we could get a few people to help out, assign each of them five or so tracks to drive, then we could cover the full game very quickly. All a helper would need to post is their lap time driving with the speed limiter on and track they drove. The best idea would be to go with the FIA style measurement and drive as close as possible to the middle of the track, and at 48mph that won't be too hard. Hmm... :)
The measurements we get won't be perfect of course, but a lot more accurate than the current ones.
mcgas001
16th January 2008, 21:59
The way i was going to do it, is switch the racing line on(4 on kb) then follow that with the limiter on :shrug:
windstyle
17th January 2008, 12:04
just pick from the mci package the speed thats the most accurate.. (thats how the km's get calculated on j4f)
Bob Smith
17th January 2008, 13:54
The best idea would be to go with the FIA style measurement and drive as close as possible to the middle of the track, and at 48mph that won't be too hard. Hmm... :)
For the purposes of this request, wouldn't it make most sense to follow the racing line as rigidly as possible?
Edit: or just do what mcgas001 said 2 posts up
mcgas001
17th January 2008, 13:58
Edit: or just do what mcgas001 said 2 posts up
:smileypul
detail
17th January 2008, 19:37
Take the world record hotlap, output .raf, read the positions from there and calculate the total distance.
yankman
17th January 2008, 19:37
I once wrote a java program to calculate track length with the pth files.
output for KY1 is
Number of Nodes: 250
FinishLine: 30
Track length: 2980m
import java.io.*;
import java.nio.ByteBuffer;
public class LFSTrackLength {
/*
1) X,Y,Z int : 32-bit fixed point world coordinates (1 metre = 65536)
X and Y are ground coordinates, Z is up.
2) float : 32 bit floating point number
FILE DESCRIPTION :
==================
num unit offset description
--- ---- ------ -----------
HEADER BLOCK :
6 char 0 LFSPTH : do not read file if no match
1 byte 6 version : 0 - do not read file if > 0
1 byte 7 revision : 0 - do not read file if > 0
1 int 8 num nodes : number
1 int 12 finish line : number
......NODE BLOCKS
NODE BLOCK :
1 int 0 centre X : fp
1 int 4 centre Y : fp
1 int 8 centre Z : fp
1 float 12 dir X : float
1 float 16 dir Y : float
1 float 20 dir Z : float
1 float 24 limit left : outer limit
1 float 28 limit right : outer limit
1 float 32 drive left : road limit
1 float 36 drive right : road limit
*/
/**
* @param args
*/
public static void main(String[] args) {
FileInputStream pth = null;
final int NodeLength = 40;
double length = 0;
byte[] buf = new byte[4000];
if(args.length < 1) {
System.out.println("Usage: java LFSTrackLength trackfile.pth");
System.exit(1);
}
try {
pth = new FileInputStream(args[0]);
} catch (IOException ioE) {
System.out.println( ioE );
System.exit(1);
}
if(pth == null) {
System.out.println( "Error gettin access to the file !");
System.exit(1);
}
// read header
try {
pth.read(buf,0,16);
} catch( IOException ioE ) {
System.out.println( ioE );
try {
pth.close();
} catch (IOException ioE2) {}
System.exit(1);
}
// check file description
if(!new String(buf,0,6).equals("LFSPTH") ||
buf[6] != 0 || buf[7] !=0) {
System.out.println("Wrong file type !");
try {
pth.close();
} catch (IOException ioE2) {}
System.exit(1);
}
ByteBuffer wrapper = ByteBuffer.wrap(buf);
wrapper.order(java.nio.ByteOrder.LITTLE_ENDIAN);
int NumNodes = wrapper.getInt(8);
System.out.println("Number of Nodes: " + NumNodes);
System.out.println("FinishLine: " + wrapper.getInt(12));
int NodesLeft = NumNodes;
int NodesRead = 0;
int[] StartPoint = null;
int[] LastPoint = null;
while(NodesLeft > 0) {
int NodesToRead = 0;
if(NodesLeft > 100) // read full buffer
NodesToRead = 100;
else
NodesToRead = NodesLeft;
try {
int BytesRead = pth.read(buf,0,NodesToRead * NodeLength);
NodesRead = BytesRead/40;
} catch( IOException ioE ) {
System.out.println( ioE );
try {
pth.close();
} catch (IOException ioE2) {}
System.exit(1);
}
for(int i = 0; i < NodesRead; i++) {
int offset = i * NodeLength;
int x = wrapper.getInt(offset);
int y = wrapper.getInt(offset + 4);
int z = wrapper.getInt(offset + 8);
// first point on path
if(StartPoint == null) {
StartPoint = new int[3];
StartPoint[0] = x;
StartPoint[1] = y;
StartPoint[2] = z;
LastPoint = new int[3];
} else { // measure distance between points
length += Math.sqrt(Math.pow(LastPoint[0] - x,2) + Math.pow(LastPoint[1] - y,2) + Math.pow(LastPoint[2] -z,2));
}
LastPoint[0] = x;
LastPoint[1] = y;
LastPoint[2] = z;
}
NodesLeft -= NodesRead;
}
length += Math.sqrt(Math.pow(LastPoint[0] - StartPoint[0],2) + Math.pow(LastPoint[1] - StartPoint[1],2) + Math.pow(LastPoint[2] - StartPoint[2],2));
System.out.println("Track length: " + Math.round(length/(double)65535) + "m");
}
}
mcgas001
17th January 2008, 19:39
Answer: 2980 m = 1.85168 mi.
J@tko
17th January 2008, 19:40
I once wrote a java program to calculate track length with the pth files.
output for KY1 is
Number of Nodes: 250
FinishLine: 30
Track length: 2980m
So thats 1.85168615216 miles.
Cheers mate :thumb:
DarkTimes
17th January 2008, 21:03
Nice. So, with the help of yankman's code I wrote a little app that parsed the lengths of every pth file and converted them into miles and kilometers, here's the output:
Track: AS1 Meters: 1870 Miles: 1.16196412904 Kilometers: 1.87
Track: AS2 Meters: 3077 Miles: 1.911959157784 Kilometers: 3.077
Track: AS3 Meters: 5602 Miles: 3.480921417584 Kilometers: 5.602
Track: AS4 Meters: 8089 Miles: 5.026271572088 Kilometers: 8.089
Track: AS5 Meters: 8802 Miles: 5.469309231984 Kilometers: 8.802
Track: AS6 Meters: 8002 Miles: 4.972212278384 Kilometers: 8.002
Track: AS7 Meters: 5168 Miles: 3.211246320256 Kilometers: 5.168
Track: AU3 Meters: 2216 Miles: 1.376958561472 Kilometers: 2.216
Track: AU4 Meters: 2216 Miles: 1.376958561472 Kilometers: 2.216
Track: BL1 Meters: 3307 Miles: 2.054874531944 Kilometers: 3.307
Track: BL2 Meters: 1839 Miles: 1.142701622088 Kilometers: 1.839
Track: FE1 Meters: 1584 Miles: 0.984251968128 Kilometers: 1.584
Track: FE2 Meters: 3086 Miles: 1.917551498512 Kilometers: 3.086
Track: FE3 Meters: 3514 Miles: 2.183498368688 Kilometers: 3.514
Track: FE4 Meters: 6559 Miles: 4.075573648328 Kilometers: 6.559
Track: FE5 Meters: 2018 Miles: 1.253927065456 Kilometers: 2.018
Track: FE6 Meters: 745 Miles: 0.46292153804 Kilometers: 0.745
Track: KY1 Meters: 2980 Miles: 1.85168615216 Kilometers: 2.98
Track: KY2 Meters: 5138 Miles: 3.192605184496 Kilometers: 5.138
Track: KY3 Meters: 7377 Miles: 4.583855283384 Kilometers: 7.377
Track: SO1 Meters: 2033 Miles: 1.263247633336 Kilometers: 2.033
Track: SO2 Meters: 2048 Miles: 1.272568201216 Kilometers: 2.048
Track: SO3 Meters: 1334 Miles: 0.828909170128 Kilometers: 1.334
Track: SO4 Meters: 4029 Miles: 2.503504532568 Kilometers: 4.029
Track: SO5 Meters: 3146 Miles: 1.954833770032 Kilometers: 3.146
Track: SO6 Meters: 2917 Miles: 1.812539767064 Kilometers: 2.917
Track: WE1 Meters: 5180 Miles: 3.21870277456 Kilometers: 5.18
Please report any weirdness, I'm crap at maths. :)
Big thanks to yankman! :D
mcgas001
17th January 2008, 21:06
Saved me a lot of work *wipes sweat off forehead*
DarkTimes
17th January 2008, 21:10
I realised there was a small bug, the updated results should be more accurate now. :)
duke_toaster
17th January 2008, 21:20
Schmexellent :)
duke_toaster
17th January 2008, 21:58
And so schmexellent I've put it in LFS Manual, but I can't be arsed to round them for miles at the moment, I might feel like it tomorrow :)
DarkTimes
17th January 2008, 22:09
I rounded them to three decimal places. If you would prefer a different rounding, let me know. Thanks for adding it to the manual. :)
Track: AS1 Miles: 1.162
Track: AS2 Miles: 1.912
Track: AS3 Miles: 3.481
Track: AS4 Miles: 5.026
Track: AS5 Miles: 5.469
Track: AS6 Miles: 4.972
Track: AS7 Miles: 3.211
Track: AU3 Miles: 1.377
Track: AU4 Miles: 1.377
Track: BL1 Miles: 2.055
Track: BL2 Miles: 1.143
Track: FE1 Miles: 0.984
Track: FE2 Miles: 1.918
Track: FE3 Miles: 2.183
Track: FE4 Miles: 4.076
Track: FE5 Miles: 1.254
Track: FE6 Miles: 0.463
Track: KY1 Miles: 1.852
Track: KY2 Miles: 3.193
Track: KY3 Miles: 4.584
Track: SO1 Miles: 1.263
Track: SO2 Miles: 1.273
Track: SO3 Miles: 0.829
Track: SO4 Miles: 2.504
Track: SO5 Miles: 1.955
Track: SO6 Miles: 1.813
Track: WE1 Miles: 3.219
Krammeh
18th January 2008, 00:41
race line on, and AI :). They follow very well. simple insim app that counts miles, sorted!
edit: should have noticed the second page before posting :P
yankman
18th January 2008, 08:45
Well of course measuring the track length with the nodes of the track is not really exact.
It is always in the middle of the track and should be quite inaccurate in tight bends.
On the other hand it is good to use it as some kind of standard cause it is defined through lfs itself and not some AI/WR racingline which might be changing in time.
But if it should be more accurate the direction vector between nodes i - 1 , i - 2 and i, i +1 could be calculated in. To get some kind of bezier curve between the nodes i and i - 1.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.