From dee8beb788ba755a7a2b5a1f857c7f4b326ea248 Mon Sep 17 00:00:00 2001 From: JasimAlrawie Date: Thu, 9 Jan 2025 17:03:44 +0300 Subject: [PATCH 1/4] math - remap function --- .../javascript/mathematical-functions/remap.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/javascript/mathematical-functions/remap.md diff --git a/snippets/javascript/mathematical-functions/remap.md b/snippets/javascript/mathematical-functions/remap.md new file mode 100644 index 00000000..ffc17377 --- /dev/null +++ b/snippets/javascript/mathematical-functions/remap.md @@ -0,0 +1,17 @@ +--- +title: Remap +description: re-maps a value from one range to another +author: JasimAlrawie +tags: math,number-theory,algebra +--- + +```js +function remap(v, start1, end1, start2, end2) { + return (v-start1) * (stop2 - start2)/(stop1 - start1) + start2 +} + +// Usage: +remap(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) +remap(value, 0, PI*2, 0, 360) // remaps the value from rad to deg +remap(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) +``` \ No newline at end of file From 5c754cc45b055ce6db1b28122432fad6636a8321 Mon Sep 17 00:00:00 2001 From: JasimAlrawie Date: Thu, 9 Jan 2025 17:19:50 +0300 Subject: [PATCH 2/4] math - remap function to most languages --- snippets/c/mathematical-functions/remap.md | 19 +++++++++++++++++++ snippets/cpp/math-and-numbers/remap.md | 19 +++++++++++++++++++ .../mathematical-functions/remap.md | 2 +- snippets/python/math-and-numbers/remap.md | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 snippets/c/mathematical-functions/remap.md create mode 100644 snippets/cpp/math-and-numbers/remap.md create mode 100644 snippets/python/math-and-numbers/remap.md diff --git a/snippets/c/mathematical-functions/remap.md b/snippets/c/mathematical-functions/remap.md new file mode 100644 index 00000000..7c78d898 --- /dev/null +++ b/snippets/c/mathematical-functions/remap.md @@ -0,0 +1,19 @@ +--- +title: Remap +description: re-maps a value from one range to another +author: JasimAlrawie +tags: math,number-theory,algebra +--- + +```c + +double remap(double v, double start1, double end1, double start2, double end2) { + return (v - start1) * (end2 - start2) / (end1 - start1) + start2; +} + + +// Usage: +remap(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) +remap(value, 0, PI*2, 0, 360) // remaps the value from rad to deg +remap(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) +``` \ No newline at end of file diff --git a/snippets/cpp/math-and-numbers/remap.md b/snippets/cpp/math-and-numbers/remap.md new file mode 100644 index 00000000..1961bb56 --- /dev/null +++ b/snippets/cpp/math-and-numbers/remap.md @@ -0,0 +1,19 @@ +--- +title: Remap +description: re-maps a value from one range to another +author: JasimAlrawie +tags: math,number-theory,algebra +--- + + +```cpp +double remap(double v, double start1, double end1, double start2, double end2) { + return (v - start1) * (end2 - start2) / (end1 - start1) + start2; +} + + +// Usage: +remap(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) +remap(value, 0, PI*2, 0, 360) // remaps the value from rad to deg +remap(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) +``` \ No newline at end of file diff --git a/snippets/javascript/mathematical-functions/remap.md b/snippets/javascript/mathematical-functions/remap.md index ffc17377..fecb55f6 100644 --- a/snippets/javascript/mathematical-functions/remap.md +++ b/snippets/javascript/mathematical-functions/remap.md @@ -6,7 +6,7 @@ tags: math,number-theory,algebra --- ```js -function remap(v, start1, end1, start2, end2) { +function remap(value, start1, end1, start2, end2) { return (v-start1) * (stop2 - start2)/(stop1 - start1) + start2 } diff --git a/snippets/python/math-and-numbers/remap.md b/snippets/python/math-and-numbers/remap.md new file mode 100644 index 00000000..3360f7fa --- /dev/null +++ b/snippets/python/math-and-numbers/remap.md @@ -0,0 +1,18 @@ +--- +title: Remap +description: re-maps a value from one range to another +author: JasimAlrawie +tags: math,number-theory,algebra +--- + +```py + +def remap(value, start1, end1, start2, end2): + return (value - start1) * (end2 - start2) / (end1 - start1) + start2 +``` + +// Usage: +remap(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) +remap(value, 0, PI*2, 0, 360) // remaps the value from rad to deg +remap(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) +``` \ No newline at end of file From 8090117876b074158f12eeb1ad20ff42b0dcea28 Mon Sep 17 00:00:00 2001 From: JasimAlrawie Date: Fri, 10 Jan 2025 00:51:57 +0300 Subject: [PATCH 3/4] remap to linearMapping, args renamed --- .../mathematical-functions/linear-mapping.md | 19 +++++++++++++++++++ snippets/c/mathematical-functions/remap.md | 19 ------------------- snippets/cpp/math-and-numbers/remap.md | 19 ------------------- .../mathematical-functions/linear-mapping.md | 17 +++++++++++++++++ .../mathematical-functions/remap.md | 17 ----------------- .../python/math-and-numbers/linear-mapping.md | 17 +++++++++++++++++ snippets/python/math-and-numbers/remap.md | 18 ------------------ 7 files changed, 53 insertions(+), 73 deletions(-) create mode 100644 snippets/c/mathematical-functions/linear-mapping.md delete mode 100644 snippets/c/mathematical-functions/remap.md delete mode 100644 snippets/cpp/math-and-numbers/remap.md create mode 100644 snippets/javascript/mathematical-functions/linear-mapping.md delete mode 100644 snippets/javascript/mathematical-functions/remap.md create mode 100644 snippets/python/math-and-numbers/linear-mapping.md delete mode 100644 snippets/python/math-and-numbers/remap.md diff --git a/snippets/c/mathematical-functions/linear-mapping.md b/snippets/c/mathematical-functions/linear-mapping.md new file mode 100644 index 00000000..d2bee181 --- /dev/null +++ b/snippets/c/mathematical-functions/linear-mapping.md @@ -0,0 +1,19 @@ +--- +title: Linear Remappibg +description: remaps a value from one range to another +author: JasimAlrawie +tags: math,number-theory,algebra +--- + +```c + +float linearMapping(float value, float minIn, float maxIn, float minOut, float maxOut) { + return (v-minIn) * (maxOut - minOut)/(maxIn - minIn) + minOut +} + + +// Usage: +linearMapping(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) +linearMapping(value, 0, PI*2, 0, 360) // remaps the value from rad to deg +linearMapping(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) +``` \ No newline at end of file diff --git a/snippets/c/mathematical-functions/remap.md b/snippets/c/mathematical-functions/remap.md deleted file mode 100644 index 7c78d898..00000000 --- a/snippets/c/mathematical-functions/remap.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: Remap -description: re-maps a value from one range to another -author: JasimAlrawie -tags: math,number-theory,algebra ---- - -```c - -double remap(double v, double start1, double end1, double start2, double end2) { - return (v - start1) * (end2 - start2) / (end1 - start1) + start2; -} - - -// Usage: -remap(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) -remap(value, 0, PI*2, 0, 360) // remaps the value from rad to deg -remap(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) -``` \ No newline at end of file diff --git a/snippets/cpp/math-and-numbers/remap.md b/snippets/cpp/math-and-numbers/remap.md deleted file mode 100644 index 1961bb56..00000000 --- a/snippets/cpp/math-and-numbers/remap.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: Remap -description: re-maps a value from one range to another -author: JasimAlrawie -tags: math,number-theory,algebra ---- - - -```cpp -double remap(double v, double start1, double end1, double start2, double end2) { - return (v - start1) * (end2 - start2) / (end1 - start1) + start2; -} - - -// Usage: -remap(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) -remap(value, 0, PI*2, 0, 360) // remaps the value from rad to deg -remap(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) -``` \ No newline at end of file diff --git a/snippets/javascript/mathematical-functions/linear-mapping.md b/snippets/javascript/mathematical-functions/linear-mapping.md new file mode 100644 index 00000000..d1afaf73 --- /dev/null +++ b/snippets/javascript/mathematical-functions/linear-mapping.md @@ -0,0 +1,17 @@ +--- +title: Linear Remapping +description: remaps a value from one range to another +author: JasimAlrawie +tags: math,number-theory,algebra +--- + +```js +function linearMapping(value, minIn, maxIn, minOut, maxOut) { + return (v-minIn) * (maxOut - minOut)/(maxIn - minIn) + minOut +} + +// Usage: +linearMapping(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) +linearMapping(value, 0, PI*2, 0, 360) // remaps the value from rad to deg +linearMapping(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) +``` \ No newline at end of file diff --git a/snippets/javascript/mathematical-functions/remap.md b/snippets/javascript/mathematical-functions/remap.md deleted file mode 100644 index fecb55f6..00000000 --- a/snippets/javascript/mathematical-functions/remap.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: Remap -description: re-maps a value from one range to another -author: JasimAlrawie -tags: math,number-theory,algebra ---- - -```js -function remap(value, start1, end1, start2, end2) { - return (v-start1) * (stop2 - start2)/(stop1 - start1) + start2 -} - -// Usage: -remap(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) -remap(value, 0, PI*2, 0, 360) // remaps the value from rad to deg -remap(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) -``` \ No newline at end of file diff --git a/snippets/python/math-and-numbers/linear-mapping.md b/snippets/python/math-and-numbers/linear-mapping.md new file mode 100644 index 00000000..d7ac833a --- /dev/null +++ b/snippets/python/math-and-numbers/linear-mapping.md @@ -0,0 +1,17 @@ +--- +title: Linear Renapping +description: remaps a value from one range to another +author: JasimAlrawie +tags: math,number-theory,algebra +--- + +```py + +def linearMapping(value, minIn, maxIn, minOut, maxOut): + return (value - minIn) * (maxOut - minOut) / (maxIn - minIn) + minOut + +// Usage: +linearMapping(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) +linearMapping(value, 0, PI*2, 0, 360) // remaps the value from rad to deg +linearMapping(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) +``` \ No newline at end of file diff --git a/snippets/python/math-and-numbers/remap.md b/snippets/python/math-and-numbers/remap.md deleted file mode 100644 index 3360f7fa..00000000 --- a/snippets/python/math-and-numbers/remap.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: Remap -description: re-maps a value from one range to another -author: JasimAlrawie -tags: math,number-theory,algebra ---- - -```py - -def remap(value, start1, end1, start2, end2): - return (value - start1) * (end2 - start2) / (end1 - start1) + start2 -``` - -// Usage: -remap(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) -remap(value, 0, PI*2, 0, 360) // remaps the value from rad to deg -remap(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) -``` \ No newline at end of file From c68d1550215a0551347680ccc357da2c128962e1 Mon Sep 17 00:00:00 2001 From: JasimAlrawie Date: Fri, 10 Jan 2025 11:42:37 +0300 Subject: [PATCH 4/4] fix all mistakes,typos --- .../c/mathematical-functions/linear-mapping.md | 11 +++++------ .../mathematical-functions/linear-mapping.md | 4 ++-- .../python/math-and-numbers/linear-mapping.md | 15 +++++++-------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/snippets/c/mathematical-functions/linear-mapping.md b/snippets/c/mathematical-functions/linear-mapping.md index d2bee181..0d4e360b 100644 --- a/snippets/c/mathematical-functions/linear-mapping.md +++ b/snippets/c/mathematical-functions/linear-mapping.md @@ -1,19 +1,18 @@ --- -title: Linear Remappibg +title: Linear Mapping description: remaps a value from one range to another author: JasimAlrawie tags: math,number-theory,algebra --- ```c - float linearMapping(float value, float minIn, float maxIn, float minOut, float maxOut) { - return (v-minIn) * (maxOut - minOut)/(maxIn - minIn) + minOut + return (value - minIn) * (maxOut - minOut)/(maxIn - minIn) + minOut; } // Usage: -linearMapping(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) -linearMapping(value, 0, PI*2, 0, 360) // remaps the value from rad to deg -linearMapping(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) +linearMapping(value, 0, 1, 0, 255); // remaps the value from (0,1) to (0,255) +linearMapping(value, 0, PI*2, 0, 360); // remaps the value from rad to deg +linearMapping(value, -1, 1, 1, 8); // remaps the value from (-1,1) to (1,8) ``` \ No newline at end of file diff --git a/snippets/javascript/mathematical-functions/linear-mapping.md b/snippets/javascript/mathematical-functions/linear-mapping.md index d1afaf73..5baada59 100644 --- a/snippets/javascript/mathematical-functions/linear-mapping.md +++ b/snippets/javascript/mathematical-functions/linear-mapping.md @@ -1,5 +1,5 @@ --- -title: Linear Remapping +title: Linear Mapping description: remaps a value from one range to another author: JasimAlrawie tags: math,number-theory,algebra @@ -7,7 +7,7 @@ tags: math,number-theory,algebra ```js function linearMapping(value, minIn, maxIn, minOut, maxOut) { - return (v-minIn) * (maxOut - minOut)/(maxIn - minIn) + minOut + return (value - minIn) * (maxOut - minOut)/(maxIn - minIn) + minOut } // Usage: diff --git a/snippets/python/math-and-numbers/linear-mapping.md b/snippets/python/math-and-numbers/linear-mapping.md index d7ac833a..3f7f5daf 100644 --- a/snippets/python/math-and-numbers/linear-mapping.md +++ b/snippets/python/math-and-numbers/linear-mapping.md @@ -1,17 +1,16 @@ --- -title: Linear Renapping +title: Linear Mapping description: remaps a value from one range to another author: JasimAlrawie tags: math,number-theory,algebra --- ```py +def linear_mapping(value, min_in, max_in, min_out, max_out): + return (value - min_in) * (max_out - min_out) / (max_in - min_in) + min_out -def linearMapping(value, minIn, maxIn, minOut, maxOut): - return (value - minIn) * (maxOut - minOut) / (maxIn - minIn) + minOut - -// Usage: -linearMapping(value, 0, 1, 0, 255) // remaps the value from (0,1) to (0,255) -linearMapping(value, 0, PI*2, 0, 360) // remaps the value from rad to deg -linearMapping(value, -1, 1, 1, 8) // remaps the value from (-1,1) to (1,8) +#Usage: +linear_mapping(value, 0, 1, 0, 255) # remaps the value from (0,1) to (0,255) +linear_mapping(value, 0, PI*2, 0, 360) # remaps the value from rad to deg +linear_mapping(value, -1, 1, 1, 8) # remaps the value from (-1,1) to (1,8) ``` \ No newline at end of file