Piecewise linear interpolation with up to 20 XY pairs; robust endpoint extrapolation.
npm install node-red-contrib-polygonPiecewise linear interpolation Node-RED node with up to 20 (X,Y) breakpoint pairs, optional endpoint extrapolation, and strict monotonic X validation.
---
polygon computes an output value from an input (msg.payload) by linearly interpolating between user-defined breakpoints. It supports 20 (X,Y) rows, each with a Use checkbox to activate the pair. Outside the endpoint range, it can extrapolate or clampâyour choice. Settings persist correctly in the editor.IN == Xk (within a tiny epsilon), OUT = Yk.msg.payload, plus msg.trbl_al, msg.n_bp, msg.segment seg k, extrap, clamped, X order invalid, etc.)~/.node-red, Docker: /data), then restart Node-RED and hard-refresh the editor.bash
cd ~/.node-red # or: cd /data (Docker)
npm install /path/to/your/node-red-contrib-polygon
node-red-restart
In browser: Ctrl+F5 to clear cached editor assets
`$3
Let the active (Use â) points be (X1,Y1)âŠ(Xn,Yn), n â„ 2, with strictly increasing X:
- If IN is inside: find k with Xk < IN < Xk+1 and compute
OUT = Yk + (IN â Xk) * (Yk+1 â Yk) / (Xk+1 â Xk)
- If exactly on a knot IN == Xk (epsilon match): OUT = Yk
- If IN < X1:
- Extrapolate ON: use slope of (X1,Y1)â(X2,Y2)
- Extrapolate OFF: OUT = Y1 (clamp)
- If IN > Xn:
- Extrapolate ON: use slope of (Xnâ1,Ynâ1)â(Xn,Yn)
- Extrapolate OFF: OUT = Yn (clamp)
- Faults (alarm true):
- Not enough points (n < 2)
- X order invalid (Xk â„ Xk+1 among used rows)Outputs
- Output 1 (OUT): computed value in
msg.payload, plus:
- msg.trbl_al â boolean: parameter fault occurred
- msg.n_bp â number of active pairs
- msg.segment â used segment index (-1 if clamped/extrapolated/knot)
- Output 2 (TRBL_AL): { payload: alarm$3
Set two points and enable extrapolation:
- Use1: X=0, Y=0
- Use2: X=10, Y=100
- Extrapolate: ONExpected:
-
IN=-5 â OUT=-50 (left extrapolation)
- IN=0 â OUT=0 (knot)
- IN=5 â OUT=50 (interpolation)
- IN=10 â OUT=100 (knot)
- IN=15 â OUT=150 (right extrapolation)$3
- Node doesnât appear in the palette: install from the userDir (~/.node-red or /data), then restart Node-RED and hard-refresh the editor (Ctrl+F5).
- Keeps clamping instead of extrapolating: ensure the Extrapolate checkbox is ON and Xâs are strictly increasing.---
đđș Magyar
$3
A polygon a bemeneti msg.payload alapjĂĄn szĂĄmĂt kimenetet a törĂ©spontok között lineĂĄris interpolĂĄciĂłval. A szerkesztĆben 20 sor ĂĄll rendelkezĂ©sre (Use, X, Y), a szĂ©lsĆ tartomĂĄnyokon pedig extrapolĂĄl vagy klampel â beĂĄllĂtĂĄstĂłl fĂŒggĆen. A beĂĄllĂtĂĄsokat helyesen megĆrzi.$3
- 20 Ă (Use, X, Y) sor
- SzigorĂșan növekvĆ X kikĂ©nyszerĂtĂ©se:
- SzerkesztĆ: a mentĂ©s (Done) nem engedĂ©lyezett, ha a pipĂĄlt sorok X Ă©rtĂ©kei nem szigorĂșan növekvĆk.
- FutĂĄsidĆ: ha hibĂĄs flow kerĂŒl be, riasztĂĄst ad (TRBL_AL).
- Végpont-kezelés vålasztható:
- ExtrapolĂĄlĂĄs (alapbĂłl BE): lineĂĄris folytatĂĄs az elsĆ/utolsĂł szakasz meredeksĂ©gĂ©vel.
- Klampelés: Y az adott végpontnål marad.
- Pontos csomópont (X-egyezés): ha IN == Xk, akkor OUT = Yk.
- Egy kimenet:
1) OUT â a bejövĆ ĂŒzenet mĂĄsolata szĂĄmĂtott msg.payload-dal, plusz msg.trbl_al, msg.n_bp, msg.segment
- ĂllapotjelzĂ©sek a debughoz (seg k, extrap, clamped, X order invalid, stb.)
$3
TelepĂts a Node-RED userDir-bĆl (jellemzĆen ~/.node-red, Dockerben /data), majd indĂtsd Ășjra a Node-RED-et Ă©s frissĂtsd a böngĂ©szĆt (Ctrl+F5).
`bash
cd ~/.node-red # vagy: cd /data (Docker)
npm install /ELERESI/UT/node-red-contrib-polygon
node-red-restart
BöngĂ©szĆ: Ctrl+F5
`$3
Legyenek az aktĂv (Use â) pontok (X1,Y1)âŠ(Xn,Yn), n â„ 2, szigorĂșan növekvĆ X-szel:
- Ha IN belĂŒl van: keresĂŒnk k-t, ahol Xk < IN < Xk+1, Ă©s szĂĄmolunk:
OUT = Yk + (IN â Xk) * (Yk+1 â Yk) / (Xk+1 â Xk)
- Ha pontosan IN == Xk: OUT = Yk
- Ha IN < X1:
- Extrap BE: az (X1,Y1)â(X2,Y2) szakasz meredeksĂ©gĂ©vel
- Extrap KI: OUT = Y1 (klampel)
- Ha IN > Xn:
- Extrap BE: az (Xnâ1,Ynâ1)â(Xn,Yn) szakasz meredeksĂ©gĂ©vel
- Extrap KI: OUT = Yn (klampel)
- HibĂĄk (TRBL_AL = true):
- Kevés pont (n < 2)
- X sorrend hibĂĄs (Xk â„ Xk+1 a hasznĂĄlt sorokban)Kimenetek
- 1. kimenet (OUT): szĂĄmĂtott
msg.payload, tovĂĄbbĂĄ:
- msg.trbl_al â logikai zĂĄszlĂł hiba esetĂ©n
- msg.n_bp â hasznĂĄlt pontpĂĄrok szĂĄma
- msg.segment â a hasznĂĄlt szegmens indexe (-1 klampelĂ©s/extrapolĂĄciĂł/csomĂłpont esetĂ©n)
- 2. kimenet (TRBL_AL): { payload: jelzĆ$3
Két pont, extrapolålås BE:
- Use1: X=0, Y=0
- Use2: X=10, Y=100Vårt értékek:
-
IN=-5 â OUT=-50
- IN=0 â OUT=0
- IN=5 â OUT=50
- IN=10 â OUT=100
- IN=15 â OUT=150$3
- Nem jelenik meg a palettĂĄn: a userDir-bĆl telepĂts (~/.node-red vagy /data`), indĂts Ășjra, Ă©s Ctrl+F5.---