Program: sr.bas
Implementation Select: Implementation
Operation Select: Program: SR.BAS
DEFDBL A-Z
' SR.BAS
' Revision 1.0 25 Jan 2001
CLS
SCREEN 12
C = 300000: c2 = C * C
c40 = 45
sx = 60 / C
ly = 180
dt = 3
L0 = 300000
v1 = L0 / dt
v2 = v1 * 2 'rest frame
l1 = L0 * SQR(1 - (v1 * v1) / c2)
l2 = L0 * SQR(1 - (v2 * v2) / c2)
state = -1
DO
LOCATE 1, 1
INPUT "state ? (0 = HELP, 1 to 3 = DEMO'S) "; a$
IF a$ <> "" THEN
nstate = VAL(a$)
IF nstate >= 0 AND nstate <= 3 THEN state = nstate ELSE END
ELSE
state = state + 1
END IF
' PRINT nstate, state: END
IF state = 2 THEN ntrain = 2 ELSE ntrain = 1
CLS
SELECT CASE state
CASE 0
LOCATE 2, 1
PRINT "This program demonstrates three demo's"
PRINT "In demo 1 there are 4 trains"
PRINT "In demo 2 there are 6 trains"
PRINT "In demo 3 there are 4 trains"
PRINT "In each demo you see the position of those trains at 5 moments"
PRINT
PRINT "In demo 1 there are 4 trains"
COLOR 7
PRINT "Train 1 stays at rest all the time"
PRINT "The three other move to the right."
PRINT "At t=6 this situation changes for the trains 3 and 4."
PRINT "At t=9 in the rest frame of the track ";
COLOR 15:
PRINT "(of train 1)"
COLOR 7:
PRINT " train 2 continues at the same speed "
PRINT " train 3 stops and train 4 moves at double speed"
PRINT "At t=9 in the rest frame of the track ";
COLOR 15:
PRINT "(of train 2)"
COLOR 7:
PRINT " the speed of train 2 is zero"
PRINT " train 3 moves to the left and train 4 moves to the right"
COLOR 15
PRINT
PRINT "In demo 2 there are 2 extra trains"
PRINT
PRINT "Demo 3 is almost identical as Demo 1,"
PRINT "except that at t=0 the trains 3 and 4 are at different positions"
COLOR 7
PRINT "At t = 6 the situation changes "
PRINT "At t = 9 train 3 moves to the right and train 4 to the left"
PRINT "at t = 12 the trains 3 and 4 are at the same position."
PRINT "The length of the trains are not equal in the frame of the track of train 1"
PRINT "Are they equal in the frame of the track of train 2 ?"
COLOR 15
PRINT "HIT ENTER TO SEE ALL THE 3 DEMO's";
CASE 1, 2
t1 = 0: t2 = 0: t3 = 0: t4 = 0
pos1 = L0
pos2 = pos1: pos3 = pos1: pos4 = pos1
FOR t = 0 TO 5
LOCATE 10 + 3 * t, 1: PRINT t * dt
IF t = 0 THEN
v11 = 0
v21 = 0
v31 = 0
L11 = L0
l21 = L0
l31 = L0
ELSE
IF t <= 2 THEN
v11 = v1
v21 = v1
L11 = l1
l21 = l1
l31 = l1
v31 = v1
ELSE
v21 = v2
l21 = l2
l31 = L0
v31 = 0
END IF
END IF
IF t > 0 THEN
t2 = t2 + dt * SQR(1 - (v11 * v11) / c2)
t1 = t * dt
pos2 = pos2 + v11 * dt '= pos1 + l0 * t
pos3 = pos3 + v21 * dt
pos4 = pos4 + v31 * dt
t3 = t3 + dt * SQR(1 - (v21 * v21) / c2)
t4 = t4 + dt * SQR(1 - (v31 * v31) / c2)
pos2rel = pos2 - pos2
pos3rel = pos3 - pos2
pos4rel = pos4 - pos2
END IF
' PRINT pos2; l1
x10 = (pos1 - L0 / 2) * sx ' train 1
x20 = (pos1 + L0 / 2) * sx ' train 1
x11 = (pos2 - L11 / 2) * sx ' train 2
x21 = (pos2 + L11 / 2) * sx ' train 2
x31 = (pos2 + L0 - L11 / 2) * sx ' train 2 set 2
x41 = (pos2 + L0 + L11 / 2) * sx ' train 2 set 2
x12 = (pos3 - l21 / 2) * sx ' train 3
x22 = (pos3 + l21 / 2) * sx ' train 3
x32 = (pos3 + L0 - l21 / 2) * sx ' train 3
x42 = (pos3 + L0 + l21 / 2) * sx ' train 3
x13 = (pos4 - l31 / 2) * sx ' train 4
x23 = (pos4 + l31 / 2) * sx ' train 4
COLOR 15
LOCATE 2, 1: PRINT TAB(8); "Length"; TAB(20); "v train";
PRINT TAB(30); "train time";
PRINT TAB(42); "rel distance"
COLOR 6
LOCATE 3, 1:
PRINT "Train 1 "; L0; TAB(20);
PRINT USING "#######"; 0; TAB(30);
PRINT USING "##.####"; t1
COLOR 15
LOCATE 4, 1:
PRINT "Train 2 "; INT(l1); TAB(20);
PRINT USING "#######"; v11; TAB(30);
PRINT USING "##.####"; t2; TAB(40);
PRINT USING "########"; pos2rel
COLOR 14
LOCATE 5, 1:
PRINT "Train 3 "; INT(l21); TAB(20);
PRINT USING "#######"; v21; TAB(30);
PRINT USING "##.####"; t3; TAB(40);
PRINT USING "########"; pos3rel
COLOR 13
LOCATE 6, 1:
PRINT "Train 4 "; INT(l31); TAB(20);
PRINT USING "#######"; v31; TAB(30);
PRINT USING "##.####"; t4; TAB(40);
PRINT USING "########"; pos4rel
' Train 1
x100 = x10: x200 = x20
FOR tx = 0 TO t + 1
COLOR 7
IF tx = 0 THEN COLOR 6
LINE (x100, ly + t * c40)-(x200, ly + t * c40)
LINE (x100, ly + t * c40 - 2)-(x100, ly + t * c40 + 2)
LINE (x200, ly + t * c40 - 2)-(x200, ly + t * c40 + 2)
x100 = x200
x200 = x200 + L0 * sx
NEXT tx
' Train 2
x110 = x11
x210 = x21
tend = t - 2
IF tend < 0 THEN tend = 0
FOR tx = 0 TO tend
COLOR 15
IF tx <> 0 THEN COLOR 7
LINE (x110, ly - 7 + t * c40)-(x210, ly - 7 + t * c40)
LINE (x110, ly - 7 + t * c40 - 2)-(x110, ly - 7 + t * c40 + 2)
LINE (x210, ly - 7 + t * c40 - 2)-(x210, ly - 7 + t * c40 + 2)
x210 = x110
x110 = x110 - l1 * sx
NEXT tx
x110 = x11
x210 = x21
FOR tx = 0 TO tend
COLOR 15
IF tx <> 0 THEN COLOR 7
LINE (x110, ly - 7 + t * c40)-(x210, ly - 7 + t * c40)
LINE (x110, ly - 7 + t * c40 - 2)-(x110, ly - 7 + t * c40 + 2)
LINE (x210, ly - 7 + t * c40 - 2)-(x210, ly - 7 + t * c40 + 2)
x110 = x210
x210 = x210 + l1 * sx
NEXT tx
IF ntrain = 2 THEN
COLOR 15
LINE (x31, ly - 7 + t * c40)-(x41, ly - 7 + t * c40)
END IF
' Train 3
COLOR 14
LINE (x12, ly - 14 + t * c40)-(x22, ly - 14 + t * c40)
IF ntrain = 2 THEN
COLOR 14
LINE (x12, ly - 14 + t * c40 - 2)-(x12, ly - 14 + t * c40 + 2)
LINE (x22, ly - 14 + t * c40 - 2)-(x22, ly - 14 + t * c40 + 2)
LINE (x32, ly - 14 + t * c40)-(x42, ly - 14 + t * c40)
END IF
' Train 4
COLOR 13
LINE (x13, ly - 21 + t * c40)-(x23, ly - 21 + t * c40)
COLOR 7
PRINT "next time"; t; : INPUT a$
NEXT t
CASE IS = 3
t1 = 0: t2 = 0: t3 = 0: t4 = 0
pos1 = 3 * L0
pos2 = pos1: pos3 = L0: pos4 = 5 * L0
FOR t = 0 TO 5
LOCATE 10 + 3 * t, 1: PRINT t * dt
IF t = 0 THEN
v11 = 0
v21 = 0
v31 = 0
L11 = L0
l21 = L0
l31 = L0
ELSE
IF t <= 2 THEN
v11 = v1
v21 = v1
L11 = l1
l21 = l1
l31 = l1
v31 = v1
ELSE
v21 = v2
l21 = l2
l31 = L0
v31 = 0
END IF
END IF
IF t > 0 THEN
t2 = t2 + dt * SQR(1 - (v11 * v11) / c2)
t1 = t * dt
pos2 = pos2 + v11 * dt '= pos1 + l0 * t
pos3 = pos3 + v21 * dt
pos4 = pos4 + v31 * dt
t3 = t3 + dt * SQR(1 - (v21 * v21) / c2)
t4 = t4 + dt * SQR(1 - (v31 * v31) / c2)
pos2rel = pos2 - pos2
pos3rel = pos3 - pos2
pos4rel = pos4 - pos2
END IF
' PRINT pos2; l1
x10 = (pos1 - L0 / 2) * sx ' train 1
x20 = (pos1 + L0 / 2) * sx ' train 1
x11 = (pos2 - L11 / 2) * sx ' train 2
x21 = (pos2 + L11 / 2) * sx ' train 2
x31 = (pos2 + L0 - L11 / 2) * sx ' train 2 set 2
x41 = (pos2 + L0 + L11 / 2) * sx ' train 2 set 2
x12 = (pos3 - l21 / 2) * sx ' train 3
x22 = (pos3 + l21 / 2) * sx ' train 3
x32 = (pos3 + L0 - l21 / 2) * sx ' train 3
x42 = (pos3 + L0 + l21 / 2) * sx ' train 3
x13 = (pos4 - l31 / 2) * sx ' train 4
x23 = (pos4 + l31 / 2) * sx ' train 4
COLOR 15
LOCATE 2, 1: PRINT TAB(8); "Length"; TAB(20); "v train";
PRINT TAB(30); "train time";
PRINT TAB(42); "rel distance"
COLOR 6
LOCATE 3, 1:
PRINT "Train 1 "; L0; TAB(20);
PRINT USING "#######"; 0; TAB(30);
PRINT USING "##.####"; t1
COLOR 15
LOCATE 4, 1:
PRINT "Train 2 "; INT(l1); TAB(20);
PRINT USING "#######"; v11; TAB(30);
PRINT USING "##.####"; t2; TAB(40);
PRINT USING "########"; pos2rel
COLOR 14
LOCATE 5, 1:
PRINT "Train 3 "; INT(l21); TAB(20);
PRINT USING "#######"; v21; TAB(30);
PRINT USING "##.####"; t3; TAB(40);
PRINT USING "########"; pos3rel
COLOR 13
LOCATE 6, 1:
PRINT "Train 4 "; INT(l31); TAB(20);
PRINT USING "#######"; v31; TAB(30);
PRINT USING "##.####"; t4; TAB(40);
PRINT USING "########"; pos4rel
' Train 1
x100 = x10: x200 = x20
FOR tx = 0 TO t + 1
COLOR 7
IF tx = 0 THEN COLOR 6
LINE (x100, ly + t * c40)-(x200, ly + t * c40)
LINE (x100, ly + t * c40 - 2)-(x100, ly + t * c40 + 2)
LINE (x200, ly + t * c40 - 2)-(x200, ly + t * c40 + 2)
x100 = x200
x200 = x200 + L0 * sx
NEXT tx
' Train 2
x110 = x11
x210 = x21
tend = t - 2
IF tend < 0 THEN tend = 0
FOR tx = 0 TO tend + 2
COLOR 15
IF tx <> 0 THEN COLOR 7
LINE (x110, ly - 7 + t * c40)-(x210, ly - 7 + t * c40)
LINE (x110, ly - 7 + t * c40 - 2)-(x110, ly - 7 + t * c40 + 2)
LINE (x210, ly - 7 + t * c40 - 2)-(x210, ly - 7 + t * c40 + 2)
x210 = x110
x110 = x110 - l1 * sx
NEXT tx
x110 = x11
x210 = x21
FOR tx = 0 TO tend + 2
COLOR 15
IF tx <> 0 THEN COLOR 7
LINE (x110, ly - 7 + t * c40)-(x210, ly - 7 + t * c40)
LINE (x110, ly - 7 + t * c40 - 2)-(x110, ly - 7 + t * c40 + 2)
LINE (x210, ly - 7 + t * c40 - 2)-(x210, ly - 7 + t * c40 + 2)
x110 = x210
x210 = x210 + l1 * sx
NEXT tx
' Train 3
COLOR 14
LINE (x12, ly - 14 + t * c40)-(x22, ly - 14 + t * c40)
' Train 4
COLOR 13
LINE (x13, ly - 21 + t * c40)-(x23, ly - 21 + t * c40)
COLOR 7
PRINT "next time"; t; : INPUT a$
NEXT t
END SELECT
LOOP UNTIL state >= 4
Back to my home page: Contents of This Document