C++ equivalent of Processing's map() function

Nathan Smith

Processing has a function map that

Re-maps a number from one range to another.

For example

int ans = map(5, 0, 10, 0, 100);

ans will be 50 as 5 is halfway between 0 and 10 and halfway between 0 and 100 is 50.

If there is no built in function how would I write my own one?

Kevin Workman

Processing is open source, and you can view the source for the map() function here.

Specifically, this is the line you care about:

float outgoing =
  start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Equivalent of Swift's .map in Objective C?

From Dev

What is C equivalent of python's map()

From Dev

What is C equivalent of python's map()

From Dev

Is there a C# equivalent to python's type() function?

From Dev

C# equivalent of Excel's TINV function

From Dev

C++ (STL map) equivalent method to Python's setdefault

From Dev

What's the equivalent of a functor map across a vector in c++

From Dev

Recreating the Processing map function in Javascript

From Dev

Is there a Groovy equivalent to Ruby's #map?

From Dev

Is there a Groovy equivalent to Ruby's #map?

From Dev

C# equivalent of Actionscript's function apply and call?

From Dev

Is there any function equivalent to Matlab's imadjust in OpenCV with C++?

From Dev

What's the Go equivalent of a C++ static const function variable?

From Dev

Is there any function equivalent to Matlab's imadjust in OpenCV with C++?

From Dev

Equivalent of hash_map::resize() in c++11's unordered_map

From Dev

is there an equivalent to Stata's egen function?

From Dev

Equivalent of python map function using lambda

From Dev

What is C# equivalent of <map> in C++?

From Dev

What is C# equivalent of <map> in C++?

From Dev

In Scala, is there an equivalent of Haskell's "fromListWith" for Map?

From Dev

What's the Ruby equivalent of map() for strings?

From Dev

What's the Ruby equivalent of map() for strings?

From Dev

Is there an equivalent of the C function mbsinvalid on Linux?

From Dev

Is there an equivalent to a nested recursive function in C?

From Dev

Clojure's equivalent to Lisp's atom function

From Dev

Python's equivalent for R's dput() function

From Dev

Java equivalent of C's poll()?

From Dev

Perl unpack "S*" equivalent in C

From Dev

What is the equivalent of a map of maps in C#

Related Related

  1. 1

    Equivalent of Swift's .map in Objective C?

  2. 2

    What is C equivalent of python's map()

  3. 3

    What is C equivalent of python's map()

  4. 4

    Is there a C# equivalent to python's type() function?

  5. 5

    C# equivalent of Excel's TINV function

  6. 6

    C++ (STL map) equivalent method to Python's setdefault

  7. 7

    What's the equivalent of a functor map across a vector in c++

  8. 8

    Recreating the Processing map function in Javascript

  9. 9

    Is there a Groovy equivalent to Ruby's #map?

  10. 10

    Is there a Groovy equivalent to Ruby's #map?

  11. 11

    C# equivalent of Actionscript's function apply and call?

  12. 12

    Is there any function equivalent to Matlab's imadjust in OpenCV with C++?

  13. 13

    What's the Go equivalent of a C++ static const function variable?

  14. 14

    Is there any function equivalent to Matlab's imadjust in OpenCV with C++?

  15. 15

    Equivalent of hash_map::resize() in c++11's unordered_map

  16. 16

    is there an equivalent to Stata's egen function?

  17. 17

    Equivalent of python map function using lambda

  18. 18

    What is C# equivalent of <map> in C++?

  19. 19

    What is C# equivalent of <map> in C++?

  20. 20

    In Scala, is there an equivalent of Haskell's "fromListWith" for Map?

  21. 21

    What's the Ruby equivalent of map() for strings?

  22. 22

    What's the Ruby equivalent of map() for strings?

  23. 23

    Is there an equivalent of the C function mbsinvalid on Linux?

  24. 24

    Is there an equivalent to a nested recursive function in C?

  25. 25

    Clojure's equivalent to Lisp's atom function

  26. 26

    Python's equivalent for R's dput() function

  27. 27

    Java equivalent of C's poll()?

  28. 28

    Perl unpack "S*" equivalent in C

  29. 29

    What is the equivalent of a map of maps in C#

HotTag

Archive