Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c9ae43c

Browse files
authored
Merge pull request #220 from JasimAlrawie/main
math - linear map function
2 parents 464e50a + c68d155 commit c9ae43c

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: Linear Mapping
3+
description: remaps a value from one range to another
4+
author: JasimAlrawie
5+
tags: math,number-theory,algebra
6+
---
7+
8+
```c
9+
float linearMapping(float value, float minIn, float maxIn, float minOut, float maxOut) {
10+
return (value - minIn) * (maxOut - minOut)/(maxIn - minIn) + minOut;
11+
}
12+
13+
14+
// Usage:
15+
linearMapping(value, 0, 1, 0, 255); // remaps the value from (0,1) to (0,255)
16+
linearMapping(value, 0, PI*2, 0, 360); // remaps the value from rad to deg
17+
linearMapping(value, -1, 1, 1, 8); // remaps the value from (-1,1) to (1,8)
18+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Linear Mapping
3+
description: remaps a value from one range to another
4+
author: JasimAlrawie
5+
tags: math,number-theory,algebra
6+
---
7+
8+
```js
9+
function linearMapping(value, minIn, maxIn, minOut, maxOut) {
10+
return (value - minIn) * (maxOut - minOut)/(maxIn - minIn) + minOut
11+
}
12+
13+
// Usage:
14+
linearMapping(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255)
15+
linearMapping(value, 0, PI*2, 0, 360) // remaps the value from rad to deg
16+
linearMapping(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8)
17+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Linear Mapping
3+
description: remaps a value from one range to another
4+
author: JasimAlrawie
5+
tags: math,number-theory,algebra
6+
---
7+
8+
```py
9+
def linear_mapping(value, min_in, max_in, min_out, max_out):
10+
return (value - min_in) * (max_out - min_out) / (max_in - min_in) + min_out
11+
12+
#Usage:
13+
linear_mapping(value, 0, 1, 0, 255) # remaps the value from (0,1) to (0,255)
14+
linear_mapping(value, 0, PI*2, 0, 360) # remaps the value from rad to deg
15+
linear_mapping(value, -1, 1, 1, 8) # remaps the value from (-1,1) to (1,8)
16+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /