Mapping 2 different ranges

   786   2   1
User Avatar
Member
350 posts
Joined: June 2016
Offline
C# and Unreal Blueprints have Mapping functionality to easilly map from 1 range to another given an input value that changes.
What options are there in Houdini?
My first range (representing degrees) goes from
270 to 120
needs to map to
45 to 135

In other words what is the mathematical relationship to go from the first range to the 2nd?
User Avatar
Member
131 posts
Joined: Aug. 2012
Offline
The fit function will work if you know your start and end ranges.
Usage: fit(value, old_min, old_max, new_min, new_max)

Example: angle = fit(angle, 120, 270, 45, 135)

I'm assuming that the reversal of values (descending, ascending) is an oversight, and that this question is related to this topic [forums.odforce.net] you posted on odforce.

The mathematical relationship to go from one range to another is as such:
For a value x between omin and omax, find the relative position of x in that range such that it falls between 0-1, and get the absolute difference between omin and omax.

Given nmin and nmax, find the absolute difference of nmin and nmax - then get the ratio of this to the difference omax-omin. Multiply the relative position of x by this difference, add nmin, and you should get newx within the range nmin-nmax.
User Avatar
Member
8525 posts
Joined: July 2007
Offline
art3mis
In other words what is the mathematical relationship to go from the first range to the 2nd?
mathematical equivalent to
float nvalue = fit(ovalue, omin, omax, nmin, nmax);
is something like:
float nvalue = clamp( nmin + (ovalue - omin) / (omax - omin) * (nmax - nmin), nmin, nmax);

however if you want non clamped result you can use
float nvalue = efit(value, omin, omax, nmin, nmax);
which is something like:
float nvalue = nmin + (ovalue - omin) / (omax - omin) * (nmax - nmin);
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links