将曲线方程映射到直线方程

时间:2014-11-30 09:52:56

标签: matlab math matplotlib curve-fitting scilab

我不知道是否可能,但我有一条曲线,我已经找到了该曲线的等式,现在我想将此曲线上的所有点映射到一条直线。 怎么做?

曲线方程:

K3x^3 + k2x^2 + k1x + k0 = y
那么什么是相应的线方程,它包含曲线中的所有点。 如果我通过使用曲线的终点来制作线方程,那么我如何将该曲线上的所有点映射或拟合到该线。

例如我附加了一个图像,因此我们可以通过使用某种方程式转换将此曲线变为直线。感谢enter image description here

我需要将输出转换为下图。 trasformed image

2 个答案:

答案 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;
        }   
}

我得到了一些线性失真的结果,可能是因为将计算值四舍五入为整数。查看我附加的输出图像。mapped image to line from a curve

答案 1 :(得分:0)

  1. 任何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约束
  2. 你想要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;
    • 整合路径长度
    • 这就是你所需要的一切
  3. curve_distance

    • 首先需要为每个点找到t参数​​
    • 一点始终是起点,所以t0 = 0
    • 您需要从参数方程和输入点坐标中找到的第二个
    • 然后只需用足够小的步长来计算距离
    • 或使用多项式代数求解并直接在O(1)
    • 中计算