Skip to content

Commit 5c754cc

Browse files
committed
math - remap function to most languages
1 parent dee8beb commit 5c754cc

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Remap
3+
description: re-maps a value from one range to another
4+
author: JasimAlrawie
5+
tags: math,number-theory,algebra
6+
---
7+
8+
```c
9+
10+
double remap(double v, double start1, double end1, double start2, double end2) {
11+
return (v - start1) * (end2 - start2) / (end1 - start1) + start2;
12+
}
13+
14+
15+
// Usage:
16+
remap(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255)
17+
remap(value, 0, PI*2, 0, 360) // remaps the value from rad to deg
18+
remap(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8)
19+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Remap
3+
description: re-maps a value from one range to another
4+
author: JasimAlrawie
5+
tags: math,number-theory,algebra
6+
---
7+
8+
9+
```cpp
10+
double remap(double v, double start1, double end1, double start2, double end2) {
11+
return (v - start1) * (end2 - start2) / (end1 - start1) + start2;
12+
}
13+
14+
15+
// Usage:
16+
remap(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255)
17+
remap(value, 0, PI*2, 0, 360) // remaps the value from rad to deg
18+
remap(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8)
19+
```

snippets/javascript/mathematical-functions/remap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tags: math,number-theory,algebra
66
---
77

88
```js
9-
function remap(v, start1, end1, start2, end2) {
9+
function remap(value, start1, end1, start2, end2) {
1010
return (v-start1) * (stop2 - start2)/(stop1 - start1) + start2
1111
}
1212

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: Remap
3+
description: re-maps a value from one range to another
4+
author: JasimAlrawie
5+
tags: math,number-theory,algebra
6+
---
7+
8+
```py
9+
10+
def remap(value, start1, end1, start2, end2):
11+
return (value - start1) * (end2 - start2) / (end1 - start1) + start2
12+
```
13+
14+
// Usage:
15+
remap(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255)
16+
remap(value, 0, PI*2, 0, 360) // remaps the value from rad to deg
17+
remap(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8)
18+
```

0 commit comments

Comments
 (0)