Initial commit
[agdavaarregn.git] / triangelstart / m / triTimes.m
blob975edead8dcebb19798a972bba37cf98dc68f044
1 %% Octave script for to generate triangle start times
3 % speed     = [ first leg, second leg, final leg ]
5 % totTimes  = [ in seconds
6 %               minute part
7 %               second part ]
9 % xTimes    = [ time on first leg in seconds
10 %               time on second leg
11 %               time on final leg ]
13 % turnTimes = [ t_1 in seconds
14 %               t_1 minute part
15 %               t_1 second part 
16 %               t_2 in seconds total
17 %               t_2 minute part
18 %               t_2 second part ]
21 %% Parameters
22 numCol = 2; % number of columns
23 printStyle = 2; % larger value for verbosity
24 totTimes = [280:-5:45]; % (s) total
25 angDeg = [110 30 40]; % (degrees) angles oposit corresponding legs
26 speedFactors = [1 0.5 1]; % speed on all legs ex: [1 0.5 1]
28 %% Perform the float calculations
29 angRad = angDeg * pi / 180; % (rad)
30 sumSinus = sin(angRad(1)) + sin(angRad(2)) + sin(angRad(3));
31 sideFactors = sumSinus * [sin(angRad(1)) sin(angRad(2)) sin(angRad(3))];
32 factor = 1 / sum(speedFactors .* sideFactors, 2);
34 numEl = numel(totTimes);
35 xTimes(1, :) = (totTimes(1, :) - 10) * factor * speedFactors(1) * sideFactors(1,1);
36 xTimes(2, :) = (totTimes(1, :) - 10) * factor * speedFactors(2) * sideFactors(1,2);
37 xTimes(3, :) = (totTimes(1, :) - 10) * factor * speedFactors(3) * sideFactors(1,3);
38 turnTimes = totTimes(1, :) - xTimes(1, :);
39 turnTimes(4, :) = turnTimes(1, :) - xTimes(2, :) - 10;
41 %% Check calculations
42 if (abs(sum(xTimes, 1) + 10 - totTimes(1,:)) > 2.2e-14)
43   error ("Check sum error 1");
44 end
45 if (abs(turnTimes(4, :) - xTimes(3, :)) > 2.2e-14)
46   error ("Check sum error 2");
47 end
49 %% Round the times and split into minutes and seconds. 
50 totTimes(1, :) = round (totTimes(1,:));
51 totTimes(3, :) = rem (totTimes(1, :), 60); % (s) second part
52 totTimes(2, :) = round ((totTimes(1, :) - totTimes(3, :))/60); % (min) minute part
53 turnTimes(1, :) = round (turnTimes(1,:));
54 turnTimes(3, :) = rem (turnTimes(1, :), 60); % (s) second part
55 turnTimes(2, :) = round ((turnTimes(1, :) - turnTimes(3,:))/60); % (min) minute part
56 turnTimes(4, :) = round (turnTimes(4,:));
57 turnTimes(6, :) = rem (turnTimes(4, :), 60); % (s) second part
58 turnTimes(5, :) = round ((turnTimes(4, :) - turnTimes(6,:))/60); % (min) minute part
59 xTimes = round (xTimes);
61 %% Print the result as formated latex code
62 numRow = ceil(numEl / numCol);
63 hStd = stdout();
64 [hStd, msg] = fopen("../input/times.tex", "w", "native");
67 fprintf(hStd, "\\begin{tabular}{");
68 for i = 1:numCol
69   fprintf(hStd, "c");
70 endfor
71 fprintf(hStd, "}\n");
73 elem = 1;
74 for i = 1:numCol
76   switch printStyle
77     case 1
78       fprintf(hStd, "\\begin{tabular}{r r}\n");
79       fprintf(hStd, "$T$ & $t_1$\\\\\n\\hline\n");
80     case 2
81       fprintf(hStd, "\\begin{tabular}{r | r r | r r r|}\n");
82       fprintf(hStd, "$T$ & $t_1$ & $t_2$ & $x_1$ & $x_2$ & $x_3$ \\\\\n\\hline\n");
83     otherwise
84       error ("Error 3");
85   endswitch
86   
87   j = 1;
88   while j <= numRow & elem <= numEl
90     switch printStyle
91       case 1
92         fprintf(hStd, "$%2.1d'\\,%2.2d''$ & $%2.1d'\\,%2.2d''$\\\\\n", ...
93                 totTimes(2, elem), ...
94                 totTimes(3, elem), ...
95                 turnTimes(2, elem), ...
96                 turnTimes(3, elem));
97       case 2
98         fprintf(hStd, "$\\mathbf{%2.1d'\\,%2.2d''}$ & $%2.1d'\\,%2.2d''$ & $%2.1d'\\,%2.2d''$ & ", ...
99                 totTimes(2, elem), ...
100                 totTimes(3, elem), ...
101                 turnTimes(2, elem), ...
102                 turnTimes(3, elem), ...
103                 turnTimes(5, elem), ...
104                 turnTimes(6, elem));
105         fprintf(hStd, "$%3.1d''$ & $%3.1d''$ & $%3.1d''$ \\\\\n", ...
106                 xTimes(1, elem), ...
107                 xTimes(2, elem), ...
108                 xTimes(3, elem));
109       otherwise
110         error ("Error 3");
111     endswitch
112         
113     if rem(j, 3) == 0
114       fprintf(hStd, "\\hline\n");
115     endif
116     j = j + 1;
117     elem = elem + 1;
118   endwhile
120   fprintf(hStd, "\\end{tabular}%%\n");
121   if i < numCol
122     fprintf(hStd, "&%%\n");
123   endif
125 endfor
126 fprintf(hStd, "\\end{tabular}\n");
127 fclose(hStd);
131