我不知道是否可能,但我有一条曲线,我已经找到了该曲线的等式,现在我想将此曲线上的所有点映射到一条直线。 怎么做?
曲线方程:
K3x^3 + k2x^2 + k1x + k0 = y
那么什么是相应的线方程,它包含曲线中的所有点。
如果我通过使用曲线的终点来制作线方程,那么我如何将该曲线上的所有点映射或拟合到该线。
例如我附加了一个图像,因此我们可以通过使用某种方程式转换将此曲线变为直线。感谢
我需要将输出转换为下图。
答案 0 :(得分:1)
所以我通过简单地从线方程中减去曲线方程来做到这一点,然后我得到了另一个方程(减去方程的结果),我用它来将所有曲线点映射到线上。
void mapCurvePointsToLine(IplImage *img, double *coeff)
{
// algo: mapping equation = line equation - curve equation
int i, y;
double m;
struct points p;
p.x = malloc(sizeof(*p.x) * img->widthStep);
p.y = malloc(sizeof(*p.y) * img->widthStep);
p.np = img->widthStep;
for( i = 0; i < img->widthStep; i++) {
y = round( (pow(i,3)*coeff[3]) + (pow(i,2)*coeff[2]) + (i*coeff[1]) + coeff[0]);
p.x[i] = i;
p.y[i] = y;
img->imageData[(y*img->widthStep) + i] = 255u;
}
//calculate slope and interspect of line
m = (p.y[(p.np - 1)] - p.y[0] ) / (p.x[(p.np - 1)] - p.x[0]);
for( i = 0; i < img->widthStep; i++) {
y = p.y[i] + round( (pow(i,3)* (-1 * coeff[3]) ) + (pow(i,2)* ( -1 * coeff[2])) + (i* ( m - coeff[1]) ) ) ;
//y = y + round( (pow(i,3)* (-1 * coeff[3]) ) + (pow(i,2)* ( -1 * coeff[2])) ) ;
img->imageData[(y*img->widthStep) + i] = 255u;
}
}
我得到了一些线性失真的结果,可能是因为将计算值四舍五入为整数。查看我附加的输出图像。
答案 1 :(得分:0)
任何2D曲线都可以这样表达:
p(t)=p0+p1*t+p2*t*t+p3*t*t*t+...
p,p0,p1,...
是向量t
是参数<0,1>
p.x(t)=x0+(x1-x0)*t+0*t*t+0*t*t*t;
p.y(t)=k0+k1*t+k2*t*t+k3*t*t*t;
x0,x1
是您的x
约束你想要q(p(t))位于p(0)+(p(1)-p(0))*u;
u
是参数<0,1>
t,u
与开始时的曲线距离成正比u=curve_distance(p(t),p(0))/curve_distane(p(1),p(0));
curve_distance
以区间&lt; 0,t&gt; curve_distance