Various formulas...
+3
graymac
BruceS
Dexter
7 posters
Page 1 of 1
Various formulas...
I will place some calculations on route creation here. Should you have any particular request, let me know. Once there is enough valuable content, it can be converted to PDF and put to our "College of Knowledge"...
1  Pitch calculation
The basic formula is: Track pitch = 1000 * elevation difference / distance for the difference
Let's put an example, where we want to descend our route by 1 meter on a 170 meters distance:
Pitch = 1000 * 1 / 170 > 1000 / 170 > 5.88 let's not forget we are descending, therefore the resulting value is  5.88
Usage in route: .pitch 5.88;
Important note, pitch has to be ended by putting another pitch with 0, pitch can only be put at the beginning of a block.
The basic formula is: Track pitch = 1000 * elevation difference / distance for the difference
Let's put an example, where we want to descend our route by 1 meter on a 170 meters distance:
Pitch = 1000 * 1 / 170 > 1000 / 170 > 5.88 let's not forget we are descending, therefore the resulting value is  5.88
Usage in route: .pitch 5.88;
Important note, pitch has to be ended by putting another pitch with 0, pitch can only be put at the beginning of a block.
Last edited by Derryck on Tue May 15, 2012 1:11 pm; edited 3 times in total
Re: Various formulas...
For a start...how's about that gradient one?
Might be useful for others...
Might be useful for others...
BruceS Posts : 77
Join date : 20110831
Location : Somwhere in the Worth Valley
Re: Various formulas...
Pitch IS gradient. Expressed as a percentage rather than a ratio.
Or, put another way, one's a decimal and one's a fraction.
Or, put another way, one's a decimal and one's a fraction.
Re: Various formulas...
graymac wrote:Pitch IS gradient. Expressed as a percentage rather than a ratio.
Or, put another way, one's a decimal and one's a fraction.
But I've got it right I guess.
Re: Various formulas...
graymac wrote:Pitch IS gradient. Expressed as a percentage rather than a ratio.
Or, put another way, one's a decimal and one's a fraction.
Don't worry, I keep getting them confused!
BruceS Posts : 77
Join date : 20110831
Location : Somwhere in the Worth Valley
Re: Various formulas...
Formulae for hour and minute arm on clock. In this example, the arms are modelled horizontally.
[Object]
States = ../Additions/clock hours.b3d ;loading the hour arm
StateFunction = 0 ;making it visible
RotateZFunction = 1.5708time/43200*6.28319 ;rotating it 90 degrees counterclockwise and then 720 degrees (two rotations) clockwise per 24h
RefreshRate = 720 ;refreshing every 12min (that's the time between two minutelines)
[Object]
States = ../Additions/clock minutes.b3d ;loading the minute arm
StateFunction = 0 ;making it visible
RotateZFunction = 1.5708time/3600*6.28319 ;rotating it 90 degrees counterclockwise and then 8640 degrees (24 rotations) clockwise per 24h
RefreshRate = 60 ;refreshing every minute
[Object]
States = ../Additions/clock hours.b3d ;loading the hour arm
StateFunction = 0 ;making it visible
RotateZFunction = 1.5708time/43200*6.28319 ;rotating it 90 degrees counterclockwise and then 720 degrees (two rotations) clockwise per 24h
RefreshRate = 720 ;refreshing every 12min (that's the time between two minutelines)
[Object]
States = ../Additions/clock minutes.b3d ;loading the minute arm
StateFunction = 0 ;making it visible
RotateZFunction = 1.5708time/3600*6.28319 ;rotating it 90 degrees counterclockwise and then 8640 degrees (24 rotations) clockwise per 24h
RefreshRate = 60 ;refreshing every minute
Quork Posts : 1422
Join date : 20120505
Age : 31
Location : Hofheim a.T., Hessen (Hesse), European Union
Re: Various formulas...
You will want the refreshrate to be faster. If your refreshrate for minutes is 60, it might be at the 59th second of the minute do the minute hand move.Quork wrote:Formulae for hour and minute arm on clock. In this example, the arms are modelled horizontally.
[Object]
States = ../Additions/clock hours.b3d ;loading the hour arm
StateFunction = 0 ;making it visible
RotateZFunction = 1.5708time/43200*6.28319 ;rotating it 90 degrees counterclockwise and then 720 degrees (two rotations) clockwise per 24h
RefreshRate = 720 ;refreshing every 12min (that's the time between two minutelines)
[Object]
States = ../Additions/clock minutes.b3d ;loading the minute arm
StateFunction = 0 ;making it visible
RotateZFunction = 1.5708time/3600*6.28319 ;rotating it 90 degrees counterclockwise and then 8640 degrees (24 rotations) clockwise per 24h
RefreshRate = 60 ;refreshing every minute
Re: Various formulas...
Well that depends on what the clock is for. For a station clock, you'd want a refresh rate of 1sec for everything; these formulae are used in my gothic building bricks for the church clock, which isn't necessarily highly accurate, that's why I purposedly took those high values. But thank you for pointing it out explicitely!
Quork Posts : 1422
Join date : 20120505
Age : 31
Location : Hofheim a.T., Hessen (Hesse), European Union
Re: Various formulas...
This has been known to work perfectly well, from the animated demonstration formerly on the Official site.
[Object]
States = Second.b3d
RotateZDirection = 0, 0, 1
RotateZFunction = floor[time] * 0.10471975511966
RotateZDamping = 20, 0.4
[Object]
States = Minute.b3d
RotateZDirection = 0, 0, 1
RotateZFunction = floor[time * 0.0166666666666667] * 0.10471975511966
RotateZDamping = 20, 0.4
[Object]
States = Hour.b3d
RotateZDirection = 0, 0, 1
RotateZFunction = floor[time * 0.000277777777777778] * 0.523598775598298
RotateZDamping = 20, 0.4
I see no point in reinventing the wheel.
[Object]
States = Second.b3d
RotateZDirection = 0, 0, 1
RotateZFunction = floor[time] * 0.10471975511966
RotateZDamping = 20, 0.4
[Object]
States = Minute.b3d
RotateZDirection = 0, 0, 1
RotateZFunction = floor[time * 0.0166666666666667] * 0.10471975511966
RotateZDamping = 20, 0.4
[Object]
States = Hour.b3d
RotateZDirection = 0, 0, 1
RotateZFunction = floor[time * 0.000277777777777778] * 0.523598775598298
RotateZDamping = 20, 0.4
I see no point in reinventing the wheel.
Distance Traveled
I had a question, there is not formula to distance traveled
i'm creating the TGV 4402 V150 Record and i had a trouble on digital panel
the PK "point kilometric" represent the distance of the route in kilometers but this time is for distance traveled.
100 Kilometer = 100000 meters
10 Kilometer = 10000 meters
1 Kilometer = 1000 meters
0,1 kilometer = 100 meters
i was thinking something like this but isn't work already.
i'm creating the TGV 4402 V150 Record and i had a trouble on digital panel
the PK "point kilometric" represent the distance of the route in kilometers but this time is for distance traveled.
100 Kilometer = 100000 meters
10 Kilometer = 10000 meters
1 Kilometer = 1000 meters
0,1 kilometer = 100 meters
i was thinking something like this but isn't work already.
 Code:
;Centena de Km
[Object]
States = Cabina3d/PK/0.csv,Cabina3d/PK/1.csv,Cabina3d/PK/2.csv,Cabina3d/PK/3.csv,Cabina3d/PK/4.csv,Cabina3d/PK/5.csv,Cabina3d/PK/6.csv,Cabina3d/PK/7.csv,Cabina3d/PK/8.csv,Cabina3d/PK/9.csv
position = 0.307,0.275,0.16
stateFunction = Distance * 100000
;Decena de Km
[Object]
States = Cabina3d/PK/0.csv,Cabina3d/PK/1.csv,Cabina3d/PK/2.csv,Cabina3d/PK/3.csv,Cabina3d/PK/4.csv,Cabina3d/PK/5.csv,Cabina3d/PK/6.csv,Cabina3d/PK/7.csv,Cabina3d/PK/8.csv,Cabina3d/PK/9.csv
position = 0.327,0.275,0.16
stateFunction = Distance * 10000
;Unidad de Km
[Object]
States = Cabina3d/PK/0.csv,Cabina3d/PK/1.csv,Cabina3d/PK/2.csv,Cabina3d/PK/3.csv,Cabina3d/PK/4.csv,Cabina3d/PK/5.csv,Cabina3d/PK/6.csv,Cabina3d/PK/7.csv,Cabina3d/PK/8.csv,Cabina3d/PK/9.csv
position = 0.347,0.275,0.16
stateFunction = Distance * 1000
;Decimal Km
[Object]
States = Cabina3d/PK/0.csv,Cabina3d/PK/1.csv,Cabina3d/PK/2.csv,Cabina3d/PK/3.csv,Cabina3d/PK/4.csv,Cabina3d/PK/5.csv,Cabina3d/PK/6.csv,Cabina3d/PK/7.csv,Cabina3d/PK/8.csv,Cabina3d/PK/9.csv
position = 0.397,0.275,0.16
stateFunction = Distance * 100
Manuel18 Posts : 75
Join date : 20121018
Age : 28
Location : Caracas,Venezuela
Re: Various formulas...
For the clock formula, can this work for creating a clock in the cab of a train? And would this be for an analog clock or can it be used for a digital clock?
buckysam Posts : 150
Join date : 20120528
Age : 26
Location : Kentucky USA
Re: Various formulas...
buckysam wrote:For the clock formula, can this work for creating a clock in the cab of a train? And would this be for an analog clock or can it be used for a digital clock?
i was talking about the PK is like a Odometer in Kilometers on this case
for the Digital Clock there isn't trouble.
Manuel18 Posts : 75
Join date : 20121018
Age : 28
Location : Caracas,Venezuela
Re: Various formulas...
I think Buckysam related to Gray's and mine posts about clocks, since he asks about clocks...
@ Buckysam: As both Graymac's and mine formulae are describing rotations, with each being 60 times slower than the next quicker one, chances are big, it's about analog clocks, isn't it? It might prove valuable to try and analyse a formula before trying to find usages for it
@ Manuel: You use "distance" wrongly. Please check back on the documentation for what the value of "distance" is. When used in a cab, it always will be 0, no matter how far you drive. What you try to do is a tough one... Problem is, you have no possibility to save a value in a variable. The only thing you can do is access the last value of the function; but since you use a digital metre and thus stateFunction, the value is always rounded, so with every calculation you lose more accuracy, in an unpredictable way; the faster a computer is, the lower the value will be (or even won't ever leave "0"), since the faster it is, the more often the stateFunction is calculated, the bigger chances are values get down and not uprounded. If you start, and the computer calculates you've done 0.4metres since the last evaluation, the value won't change, as the 0.4 will be downrounded to 0 again. "value + delta * speedometer" best describes the distance travelled; but I have no idea how to put this in a way for digital display. It would be possible to have an analogue metre, as there you don't need rounding and can keep exact values all the time. That might be an idea though... I see you're even (a bit) younger than me, but maybe you still remember MC recorders nonetheless? They often had an analogue digit display. Also I think there have been such clocks. They work as follows:
For each digit, you have one ring with all 10 ciffers on it. And every digit moves ten times slower than the one right to it. So when the 1m digit rotates ten times, the 10m digit rotates once; when the 10m digit rotates ten times, the 100m digit rotates once; and so on. So this might do the trick:
For 10cm digit:
RotateXFunction = value + delta * speedometer / 3.14159
For 1m digit:
RotateXFunction = value + delta * speedometer / (3.14159 * 10)
For 10m:
RotateXFunction = value + delta * speedometer / (3.14159 * 100)
and so on.
Get what I mean?
@ Buckysam: As both Graymac's and mine formulae are describing rotations, with each being 60 times slower than the next quicker one, chances are big, it's about analog clocks, isn't it? It might prove valuable to try and analyse a formula before trying to find usages for it
@ Manuel: You use "distance" wrongly. Please check back on the documentation for what the value of "distance" is. When used in a cab, it always will be 0, no matter how far you drive. What you try to do is a tough one... Problem is, you have no possibility to save a value in a variable. The only thing you can do is access the last value of the function; but since you use a digital metre and thus stateFunction, the value is always rounded, so with every calculation you lose more accuracy, in an unpredictable way; the faster a computer is, the lower the value will be (or even won't ever leave "0"), since the faster it is, the more often the stateFunction is calculated, the bigger chances are values get down and not uprounded. If you start, and the computer calculates you've done 0.4metres since the last evaluation, the value won't change, as the 0.4 will be downrounded to 0 again. "value + delta * speedometer" best describes the distance travelled; but I have no idea how to put this in a way for digital display. It would be possible to have an analogue metre, as there you don't need rounding and can keep exact values all the time. That might be an idea though... I see you're even (a bit) younger than me, but maybe you still remember MC recorders nonetheless? They often had an analogue digit display. Also I think there have been such clocks. They work as follows:
For each digit, you have one ring with all 10 ciffers on it. And every digit moves ten times slower than the one right to it. So when the 1m digit rotates ten times, the 10m digit rotates once; when the 10m digit rotates ten times, the 100m digit rotates once; and so on. So this might do the trick:
For 10cm digit:
RotateXFunction = value + delta * speedometer / 3.14159
For 1m digit:
RotateXFunction = value + delta * speedometer / (3.14159 * 10)
For 10m:
RotateXFunction = value + delta * speedometer / (3.14159 * 100)
and so on.
Get what I mean?
Quork Posts : 1422
Join date : 20120505
Age : 31
Location : Hofheim a.T., Hessen (Hesse), European Union
Re: Various formulas...
You can make a speedometer as an animated obj in a 3D cab. A odometer (distance readout) is not possible, as far as I can tell. (see functions, below, from OpenBVE guide)
● Trains (general)
Variable Description
cars The number of cars the train has.
speed The signed actual speed of the current car in m/s. Is positive when the train travels forward, and negative when the train travels backward.
speed[carIndex] The signed actual speed of the car carIndex in m/s. Is positive when the train travels forward, and negative when the train travels backward.
speedometer The signed perceived speed of the current car in m/s as it would appear to a speedometer on wheel slip and wheel lock.
speedometer[carIndex] The signed perceived speed of the car carIndex in m/s as it would appear to a speedometer on wheel slip and wheel lock.
acceleration The actual acceleration of the current car in m/s².
acceleration[carIndex] The actual acceleration of the car carIndex in m/s².
accelerationMotor The acceleration which the motor of the first motor car currently generates in m/s².
accelerationMotor[carIndex] The acceleration which the motor of the car carIndex currently generates in m/s².
distance The nonnegative cartesian distance measured from the object to the closest car in meters. Only meaningful for scenery objects.
distance[carIndex] The nonnegative cartesian distance measured from the object to the car carIndex in meters, or 0 if the car does not exist. Only meaningful for scenery objects.
trackDistance The signed track distance measured from the object to the closest end of the train in meters. Is positive when the train is in front of the object, negative when behind, and zero when the object lies between the ends of the train. Only meaningful for scenery objects. Deprecated. The behavior of this variable may change in future versions of openBVE.
trackDistance[carIndex] The signed track distance measured from the object to the car carIndex in meters. Is positive when the center of the car is in front of the object, and negative if behind. Returns 0 if the car does not exist. Only meaningful for scenery objects. Deprecated. The behavior of this variable may change in future versions of openBVE.
Re: Various formulas...
Quork wrote:I think Buckysam related to Gray's and mine posts about clocks, since he asks about clocks...
@ Buckysam: As both Graymac's and mine formulae are describing rotations, with each being 60 times slower than the next quicker one, chances are big, it's about analog clocks, isn't it? It might prove valuable to try and analyse a formula before trying to find usages for it
Mainly, it's about digital clocks. Most trains I've used already have a digital clock in the cab, but it's just a static object. I want to try adding a working digital clock in them so i don't have to use the function to display the clock. There is a train I have that the digital clock in the cab is fully working. I want to replicate that in other trains.
buckysam Posts : 150
Join date : 20120528
Age : 26
Location : Kentucky USA
Re: Various formulas...
Well I do understand you, Buckysam, but the formulae presented here are pretty obviously ones for analog clocks. A digital clock isn't hard to do, it's a simple matter of state functions and cycling through 10 objects for each digit.
Graymac, don't you think my idea for the odometre would work? It isn't 100% accurate, that's obvious, but it should work nonetheless. Or is there an error in my thoughts?
Graymac, don't you think my idea for the odometre would work? It isn't 100% accurate, that's obvious, but it should work nonetheless. Or is there an error in my thoughts?
Quork Posts : 1422
Join date : 20120505
Age : 31
Location : Hofheim a.T., Hessen (Hesse), European Union
Re: Various formulas...
buckysam wrote:Quork wrote:I think Buckysam related to Gray's and mine posts about clocks, since he asks about clocks...
@ Buckysam: As both Graymac's and mine formulae are describing rotations, with each being 60 times slower than the next quicker one, chances are big, it's about analog clocks, isn't it? It might prove valuable to try and analyse a formula before trying to find usages for it
Mainly, it's about digital clocks. Most trains I've used already have a digital clock in the cab, but it's just a static object. I want to try adding a working digital clock in them so i don't have to use the function to display the clock. There is a train I have that the digital clock in the cab is fully working. I want to replicate that in other trains.
My French TGV POS 4402 had it
;Hora Digital
;10 Hours
[Object]
States = 0.csv,1.csv,2.csv,3.csv,4.csv,5.csv,6.csv,7.csv,8.csv,9.csv
Position = 0.5, 2.1, 12.86
stateFunction = floor[time/36000]
;1 Hour
[Object]
States = 0.csv,1.csv,2.csv,3.csv,4.csv,5.csv,6.csv,7.csv,8.csv,9.csv
Position = 0.525, 2.1, 12.86
stateFunction = floor[mod[time/3600,10]]
;separator
[Object]
States = separateurd.csv,separateurdnoir.csv
Position = 0.55, 2.1, 12.86
StateFunction = value == 0
RefreshRate = 0.5
;10 minutes
[Object]
States = 0.csv,1.csv,2.csv,3.csv,4.csv,5.csv,6.csv,7.csv,8.csv,9.csv
Position = 0.575, 2.1, 12.86
stateFunction = floor[mod[time/60,60]*0.1]
; 1 minute
[Object]
States = 0.csv,1.csv,2.csv,3.csv,4.csv,5.csv,6.csv,7.csv,8.csv,9.csv
Position = 0.6, 2.1, 12.86
stateFunction = floor[mod[mod[time/60,60],10]]
Manuel18 Posts : 75
Join date : 20121018
Age : 28
Location : Caracas,Venezuela
Re: Various formulas...
Graymac, don't you think my idea for
the odometre would work? It isn't 100% accurate, that's obvious, but it
should work nonetheless. Or is there an error in my thoughts?
I think you know more about this subject than I do. Trainbuilding's not my speciality, plus I only know the panel2 cab method. As for animated format, my animated objects are nearly all based on "found items" like the examples in the OpenBVE demo route. You would have to try your theory to see if it works or not.
Re: Various formulas...
So... I have played with the clock formula from the original documentation and unfortunately the hour thingy is not very satisfactory. The screen below actually shows 1:51... this thing needs to be polished. Other than that, the clock is already animated in my route.
Re: Various formulas...
I use an animated analog clock in Kilmagranny. The coding for this is taken from the example in the former official OpenBVE Demo route with the textures being unique to the route.
Always ask yourself how much time it is worth spending on minor details before wasting it. Unless any object is seen close enough and for long enough it may be possible to allow some inaccuracy or a little less detail in order to get on with the job.
Always ask yourself how much time it is worth spending on minor details before wasting it. Unless any object is seen close enough and for long enough it may be possible to allow some inaccuracy or a little less detail in order to get on with the job.
Re: Various formulas...
Wise man yerself, graymac. You might indeed be correct it would be a waste of time. I might look into that in a bit of spare time (ala never ). If I find a modification, I am sure, you will use it as well...
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum

