Created
July 2, 2022 09:55
-
-
Save estama/9052fbecbd4fbc424e43e0b7a399f055 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function monotonicSteffen(y0, y1, y2, y3, x0, x1, x2, x3, x) | |
| local x1x0, x2x1, x3x2 = x1-x0, x2-x1, x3-x2 | |
| local delta0, delta1, delta2 = (y1-y0) / (x1x0 + 1e-30), (y2-y1) / (x2x1 + 1e-30), (y3-y2) / (x3x2 + 1e-30) | |
| local m1 = (sign(delta0)+sign(delta1)) * min(abs(delta0),abs(delta1), 0.5*abs((x2x1*delta0 + x1x0*delta1) / (x2-x0 + 1e-30))) | |
| local m2 = (sign(delta1)+sign(delta2)) * min(abs(delta1),abs(delta2), 0.5*abs((x3x2*delta1 + x2x1*delta2) / (x3-x1 + 1e-30))) | |
| local xx1 = x - x1 | |
| local xrel = xx1 / max(x2x1, 1e-30) | |
| return y1 + xx1*(m1 + xrel*(delta1 - m1 + (xrel - 1)*(m1 + m2 - 2*delta1))) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment