Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/Linear.java @ 3774:a66df8e8d3df
flys-artifacts: Removed some superfluous implementations of FacetTypes.
flys-artifacts/trunk@5480 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 16 Sep 2012 08:51:14 +0000 |
parents | da1969b05292 |
children |
line wrap: on
line source
package de.intevation.flys.artifacts.math; public final class Linear implements Function { private double m; private double b; public Linear( double x1, double x2, double y1, double y2 ) { // y1 = m*x1 + b // y2 = m*x2 + b // y2 - y1 = m*(x2 - x1) // m = (y2 - y1)/(x2 - x1) # x2 != x1 // b = y1 - m*x1 if (x1 == x2) { m = 0; b = 0.5*(y1 + y2); } else { m = (y2 - y1)/(x2 - x1); b = y1 - m*x1; } } public static final double linear( double x, double x1, double x2, double y1, double y2 ) { // y1 = m*x1 + b // y2 = m*x2 + b // y2 - y1 = m*(x2 - x1) // m = (y2 - y1)/(x2 - x1) # x2 != x1 // b = y1 - m*x1 if (x1 == x2) { return 0.5*(y1 + y2); } double m = (y2 - y1)/(x2 - x1); double b = y1 - m*x1; return x*m + b; } @Override public double value(double x) { return m*x + b; } public static final double factor(double x, double p1, double p2) { // 0 = m*p1 + b <=> b = -m*p1 // 1 = m*p2 + b // 1 = m*(p2 - p1) // m = 1/(p2 - p1) # p1 != p2 // f(x) = x/(p2-p1) - p1/(p2-p1) <=> (x-p1)/(p2-p1) return p1 == p2 ? 0.0 : (x-p1)/(p2-p1); } public static final double weight(double factor, double a, double b) { //return (1.0-factor)*a + factor*b; return a + factor*(b-a); } public static final void weight( double factor, double [] a, double [] b, double [] c ) { int N = Math.min(Math.min(a.length, b.length), c.length); for (int i = 0; i < N; ++i) { c[i] = weight(factor, a[i], b[i]); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :