ultimatepp/uppdev/MySupport/geom.cpp
cxl 4a1c627474 Adding uppdev....
git-svn-id: svn://ultimatepp.org/upp/trunk@328 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2008-08-15 08:36:24 +00:00

25 lines
722 B
C++

#include "support.h"
double LinearInterpolation(double x, Point_<double> p1, Point_<double> p2, bool yx) {
double y, k;
if(!yx) {
k = ((p2.y - p1.y) / (p2.x - p1.x));
if(k >= 0) y = x - (p1.x * k) + p1.y;
else y = (p1.x * k) - x + p1.y;
}
else {
k = ((p2.y - p1.y) / (p2.x - p1.x));
if(k < 0) y = p2.x - ((p2.x - x) * k);
else y = p1.x + ((x - p1.y) / k); // 20.07.2005 provato - OK
}
#ifdef _WITH_DEBUG
RLOG("\nLinearInterpolation()");
RLOG("k: " + FormatDouble(k));
RLOG("x: " + FormatDouble(x));
RLOG("p1: " + FormatDouble(p1.x) + "," + FormatDouble(p1.y));
RLOG("p2: " + FormatDouble(p2.x) + "," + FormatDouble(p2.y));
RLOG("y: " + FormatDouble(y));
#endif
return y;
}