首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将曲线方程映射到直线方程

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

Stack Overflow用户
提问于 2014-11-30 17:52:56
回答 2查看 1.8K关注 0票数 0

我不知道这是否可能,但我有一条曲线,我已经找到了这条曲线的方程,现在我想把这条曲线上的所有点映射到一条直线上。如何做到这一点?

曲线方程:

代码语言:javascript
复制
K3x^3 + k2x^2 + k1x + k0 = y

然后是对应的直线方程,它包含了曲线上的所有点。如果我用曲线的端点建立一个直线方程,那么如何将曲线上的所有点映射或拟合到这条直线上。

例如,我附加了一张图像,所以我们可以通过某种方程转换将这条曲线变成一条直线。谢谢

我需要输出转换为以下图像。

EN

回答 2

Stack Overflow用户

发布于 2014-11-30 20:44:50

所以我只需要从直线方程中减去曲线方程,然后我就得到了另一个方程(方程减去的结果),我用它把曲线上的所有点映射到直线上。

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2014-11-30 20:48:49

  1. 任何2D曲线都可以这样表示:

代码语言:javascript
复制
- `p(t)=p0+p1*t+p2*t*t+p3*t*t*t+...`
- where `p,p0,p1,...` are vectors
- `t` is parameter `<0,1>`
- you already have this
- `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;`
- which is the same ...
- `x0,x1` are your `x` constraints

你想要位于行p(0)+(p(1)-p(0))*u;上的q(p(t)) (p(T))(

  1. )

代码语言:javascript
复制
- where `u` is parameter `<0,1>`
- so if we assume that parameters `t,u` are proportional to curve distance from start
- then `u=curve_distance(p(t),p(0))/curve_distane(p(1),p(0));`
- so write function `curve_distance` that integrates the path length at interval <0,t>
- and that is all you need

  1. curve_distance

代码语言:javascript
复制
- first you need to find the t parameter for each point
- one point is always the start point so t0=0
- the second you need to find from your parametric equations and input point coordinates
- then just write for cycle with small enough step summing the distance
- or solve it algebraically for used polynomial and compute directly in O(1)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27211991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档