/
index.php
138 lines (133 loc) · 5.48 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<?php
// loads the variable $varName from the url
// if no url input is found it checks for a cookie with the same name
// if no such cookie is found it uses the $defaultValue
// store the value in a cookie named $varName with a default lifetime of 30 days
// returns the result
function loadVariable($varName, $defaultValue, $cookieLifetime = 2592000) {
$varValue = $_GET[$varName]; // fetches the variable from the url
if (!is_numeric($varValue)) { // the fetched input is not numeric or not valid
if (isset($_COOKIE[$varName])) { // a cookie with the same name is found
$varValue = $_COOKIE[$varName]; // use the cookie
} else { // no cookie is found
$varValue = $defaultValue; // use the default value
}
}
setcookie($varName, $varValue, time() + $cookieLifetime); // sets a cookie
return $varValue; // returns the result
}
// initilize all variables
$distance = loadVariable("distance", 60);
$tension = loadVariable("tension", 10);
$mass = loadVariable("mass", 100);
$sag = loadVariable("sag", 1.5);
$angle = loadVariable("angle", 5.6);
?>
<html>
<head>
<title>Slackline Tension</title>
<link rel="manifest" href="manifest.json">
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<br>
<table id="input">
<form>
<tr>
<td><label for="tension">tension:</label></td>
<td><input id="tension" name="tension" type="number" step="0.1"
value = <?php echo "\"" . $tension ."\"" ?></td>
<td>kN</td>
</tr>
<tr>
<td><label for="distance">distance:</label></td>
<td><input id="distance" name="distance" type="number" step="1"
value = <?php echo "\"" . $distance ."\"" ?></td>
<td>m</td>
</tr>
<tr>
<td><label for="mass">mass:</label></td>
<td><input id="mass" name="mass" type="number" step="1"
value = <?php echo "\"" . $mass ."\"" ?></td>
<td>kg</td>
</tr>
<tr>
<td></td>
<td><button>calculate sag</button></td>
<td></td>
</tr>
<tr>
<td>sag:</td>
<td><?php
$calculatedSag = tan(asin((9.81*$mass)/(2000*$tension))) * $distance/2;
echo number_format($calculatedSag, 2);
?></td>
<td>m</td>
</tr>
</form>
<tr><td><br></td></tr>
<form>
<tr>
<td><label for="sag">sag:</label></td>
<td><input id="sag" name="sag" type="number" step="0.01"
value = <?php echo "\"" . $sag ."\"" ?></td>
<td>m</td>
</tr>
<tr>
<td><label for="distance">distance:</label></td>
<td><input id="distance" name="distance" type="number" step="1"
value = <?php echo "\"" . $distance ."\"" ?></td>
<td>m</td>
</tr>
<tr>
<td><label for="mass">mass:</label></td>
<td><input id="mass" name="mass" type="number" step="1"
value = <?php echo "\"" . $mass ."\"" ?></td>
<td>kg</td>
</tr>
<tr>
<td></td>
<td><button>calculate tension</button></td>
<td></td>
</tr>
<tr>
<td>tension:</td>
<td><?php
$calculatedTension = ( 9.81 * $mass ) / ( 2000 * sin(atan((2*$sag)/$distance)) );
echo number_format($calculatedTension, 1);
?></td>
<td>kN</td>
</tr>
</form>
<tr><td><br></td></tr>
<form>
<tr>
<td><label for="angle">angle:</label></td>
<td><input id="angle" name="angle" type="number" step="0.1"
value = <?php echo "\"" . $angle ."\"" ?></td>
<td>°</td>
</tr>
<tr>
<td><label for="mass">mass:</label></td>
<td><input id="mass" name="mass" type="number" step="1"
value = <?php echo "\"" . $mass ."\"" ?></td>
<td>kg</td>
</tr>
<tr>
<td></td>
<td><button>calculate tension</button></td>
<td></td>
</tr>
<tr>
<td>tension:</td>
<td><?php
$calculatedTension = 9.81 * $mass / ( 2000 * sin( pi() * $angle / 360 ) );
echo number_format($calculatedTension, 1);
?></td>
<td>kN</td>
</tr>
</form>
</table>
</body>
</html>