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 dee8beb

Browse files
math - remap function
1 parent f9fa07b commit dee8beb

File tree

1 file changed

+17
-0
lines changed
  • snippets/javascript/mathematical-functions

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
```js
9+
function remap(v, start1, end1, start2, end2) {
10+
return (v-start1) * (stop2 - start2)/(stop1 - start1) + start2
11+
}
12+
13+
// Usage:
14+
remap(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255)
15+
remap(value, 0, PI*2, 0, 360) // remaps the value from rad to deg
16+
remap(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8)
17+
```

0 commit comments

Comments
(0)

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