normalize

koadrobot/aritmatics/normalize

Normalize X in Start..Stop. Clip X. Output is Norm (0..1.0). Start is 0 of Norm, Stop is 1.0 of Norm. X=-2, Start=10, Stop=0 then Norm is 1.2. Normalize= (X-Start) / (Stop-Start) Sdiff : +..+..--..-- Tdiff : +..--..+..-- Norm=+..--..--..+
normalize
@/normalize
Normalize X in Start..Stop. Clip X. Output is Norm (0..1.0). Start is 0 of Norm, Stop is 1.0 of Norm. X=-2, Start=10, Stop=0 then Norm is 1.2. Normalize= (X-Start) / (Stop-Start) Sdiff : +..+..--..-- Tdiff : +..--..+..-- Norm=+..--..--..+
Xnumber
Value to map
STARTnumber
Source range begin bound
STOPnumber
Source range end bound
normalize
OUT
X
START
STOP
OUTnumber
Normalize as Duty (0..1.0)
To use the node in your project you should have the koadrobot/aritmatics library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD dirtieness disable

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    Number x = getValue<input_X>(ctx);
    Number start = getValue<input_START>(ctx);
    Number stop = getValue<input_STOP>(ctx);
    Number outX = (x-start)/(stop-start);
    emitValue<output_OUT>(ctx, outX);
}

Tabular tests

XSTARTSTOPOUT
20100.2
21000.8
20-10-0.2
2-1001.2
-2010-0.2
-21001.2
-20-100.2
-2-1000.8
2000
00100