-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
202 lines (161 loc) · 9.9 KB
/
index.html
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Latest compiled and minified BOOTSTRAP CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- Custom styles for this template -->
<link href="css/style.css" rel="stylesheet">
<title>Online range scaling tool</title>
</head>
<body>
<header>
<div class="collapse bg-dark" id="navbarHeader">
<div class="container">
<div class="row">
<div class="col-sm-8 col-md-7 py-4">
<h4 class="text-white">About</h4>
<p class="text-muted">This tool is used to convert a value from a range to another knowing the min and the max of the current range, and the new min and max of the new range.
</p>
<p class="text-muted">I was looking for such kind of online tool for some time and I couldn't find any so I decided to create this website and also explain how to convert to the new range.
</p>
</div>
<div class="col-sm-4 offset-md-1 py-4">
<h4 class="text-white">Contact</h4>
<p class="text-muted">If you have any questions about this tool this is the <a href="https://github.com/combatistor/online-mapping">GitHub repo</a>
</p>
<!-- <ul class="list-unstyled">
<li><a href="#" class="text-white">Follow on Twitter</a></li>
<li><a href="#" class="text-white">Like on Facebook</a></li>
<li><a href="#" class="text-white">Email me</a></li>
</ul> -->
</div>
</div>
</div>
</div>
<div class="navbar navbar-dark bg-dark shadow-sm">
<div class="container d-flex justify-content-between">
<a href="#" class="navbar-brand d-flex align-items-center">
Online range scaling tool
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarHeader" aria-controls="navbarHeader" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</div>
</header>
<div class="container pt-3 pb-3">
<div class="dropdown mt-3 mb-4">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Linear mapping
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Linear mapping</a>
<a class="dropdown-item" href="#">Logarithm mapping</a>
</div>
</div>
<form class="needs-validation" novalidate id="myForm">
<div class="input-group mb-4">
<div class="input-group-prepend">
<span class="input-group-text" id="value">x</span>
</div>
<input id="x" type="number" class="form-control" placeholder="Value to rescale" aria-label="Value" aria-describedby="value" required>
<div class="invalid-feedback">Please enter a value.</div>
</div>
<div id="div-min_max" class="input-group mb-4">
<div class="input-group-prepend">
<span class="input-group-text">min - max</span>
</div>
<input id="min" type="number" class="form-control" placeholder="Current range min" aria-label="min" required>
<input id="max" type="number" class="form-control" placeholder="Current range max" aria-label="max" required>
<div id="min-max-feedback" class="invalid-feedback"></div>
</div>
<div class="input-group mb-4">
<div class="input-group-prepend">
<span class="input-group-text">a - b</span>
</div>
<input id="a" type="number" class="form-control" placeholder="New range min" aria-label="min" required>
<input id="b" type="number" class="form-control" placeholder="New range max" aria-label="max" required>
<div id="a-b-feedback" class="invalid-feedback"></div>
</div>
</form>
<button id="button-convert" type="submit" class="btn btn-secondary btn-lg btn-block mb-5" onclick="convert()">Convert!</button>
<h1 class="text-break mb-5" id="result">Result:</h1>
<button class="btn btn-secondary" type="button" data-toggle="collapse" data-target="#collapseDetails" aria-expanded="false" aria-controls="collapseDetails">
Details
</button>
<div id="collapseDetails" class="collapse">
<div class="card card-body">
<div class="d-none d-lg-block">
<p>
In order to scale a range [min, max] to [a, b], you are looking for a continuous function that satisfies:
\[f(min) = a \quad and \quad f(max) = b\]
We can start by mapping [min, max] into the range [0, 1].
Putting min into a function and getting out 0 can be done with:
\[f(\color{red} min \color{black}) = \color{red} min \color{black} - min = 0 \quad \Longrightarrow \quad f(x) = x - min \]
\[But\]
\[f(\color{red} max \color{black}) = \color{red} max \color{black} - min \neq 1 \]
So we have to scale it:
\[f(\color{red} min \color{black}) = \frac{\color{red} min \color{black} - min}{max-min} = 0 \hspace{ 2pt }; \quad f(\color{red} max \color{black}) = \frac{ \color{red} max \color{black} - min}{max - min} = 1 \quad \Longrightarrow \quad
f(x) = \frac{x - min}{max - min}\]
In order to get the final function, we need to replace 0 and 1 by a and b, meaning to apply a translation and a scaling:
\[f(\color{red} min \color{black}) = \frac{ \color{red} min \color{black} - min}{max - min} = a \hspace{ 2pt }; \quad f(\color{red} max \color{black}) = \frac{\color{red} max \color{black} - min}{max-min} = b \quad \Longrightarrow \quad
f(x) = \frac{x - min}{max - min} * (b-a) + a\]
<br>
\[f(x) = (x-min)\frac{b-a}{max-min}+a\]
</p>
</div>
<div class="d-none d-md-block d-lg-none">
<p>
In order to scale a range [min, max] to [a, b], you are looking for a continuous function that satisfies:
\[f(min) = a \quad and \quad f(max) = b\]
We can start by mapping [min, max] into the range [0, 1].
Putting min into a function and getting out 0 can be done with:
\[f(\color{red} min \color{black}) = \color{red} min \color{black} - min = 0 \quad \Longrightarrow \quad f(x) = x - min \]
\[But\]
\[f(\color{red} max \color{black}) = \color{red} max \color{black} - min \neq 1 \]
So we have to scale it:
\[f(\color{red} min \color{black}) = \frac{\color{red} min \color{black} - min}{max-min} = 0 \hspace{ 2pt }; \quad f(\color{red} max \color{black}) = \frac{\color{red} max \color{black} - min}{max - min} = 1 \]
\[\Longrightarrow \quad f(x) = \frac{x - min}{max - min}\]
In order to get the final function, we need to replace 0 and 1 by a and b, meaning to apply a translation and a scaling:
\[f(\color{red} min \color{black}) = \frac{\color{red} min \color{black} - min}{max-min} = a \hspace{ 2pt }; \quad f(\color{red} max \color{black}) = \frac{\color{red} max \color{black} - min}{max - min} = b \]
\[\Longrightarrow \quad f(x) = \frac{x - min}{max - min} * (b-a) + a\]
<br>
\[f(x) = (x-min)\frac{b-a}{max-min}+a\]
</p>
</div>
<div class="d-block d-sm-block d-md-none">
<p>
In order to scale a range [min, max] to [a, b], you are looking for a continuous function that satisfies:
\[f(min) = a \quad and \quad f(max) = b\]
We can start by mapping [min, max] into the range [0, 1].
Putting min into a function and getting out 0 can be done with:
\[f(\color{red} min \color{black}) = \color{red} min \color{black} - min = 0\]
\[\Longrightarrow \quad f(x) = x - min\]
\[But\]
\[f(\color{red} max \color{black}) = \color{red} max \color{black} - min \neq 1 \]
So we have to scale it:
\[f(\color{red} min \color{black}) = \frac{\color{red} min \color{black} - min}{max - min} = 0 \]
\[f(\color{red} max \color{black}) = \frac{\color{red} max \color{black} - min}{max - min} = 1 \]
\[\Longrightarrow \quad f(x) = \frac{x - min}{max - min}\]
In order to get the final function, we need to replace 0 and 1 by a and b, meaning to apply a translation and a scaling:
\[f(\color{red} min \color{black}) = \frac{\color{red} min \color{black} - min}{max-min} = a \]
\[f(\color{red} max \color{black}) = \frac{\color{red} max \color{black} - min}{max-min} = b \]
\[\Longrightarrow \quad f(x) = \frac{x - min}{max - min} * (b-a) + a\]
<br>
\[f(x) = (x-min)\frac{b-a}{max-min}+a\]
</p>
</div>
</div>
</div>
</div>
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script src="js/script.js"></script>
</body>
</html>