Synchronize intersection points of two pairs of curves with fminsearch

前端 未结 1 908
盖世英雄少女心
盖世英雄少女心 2021-01-19 07:35

I have two pairs of curves and every pair has an intersection point at a different time value (x-value). Now I need to move one curve of each pair e

1条回答
  •  借酒劲吻你
    2021-01-19 08:12

    There is no need for fmincon - the error finally was a quite simple one.

    In this line: t2 = t2 - d I assummed t2 would be the original one from the initial function call, but thats not right. It is overwritten with every iteration and therefore increasing gradually.

    A temporary variable tt solved the problem.

    Final result:

    function [ t1,x1,y1,t2,x2,y2 ] = findIntersectPair(t1,x1,y1,t2,x2,y2)
    
    [d,dxy] = fminsearch(@findDelay,0);
    
    function dxy = findDelay( d )
        tt = t2 - d;
        ipx = InterX([t1;x1],[tt;x2]);
        ipy = InterX([t1;y1],[tt;y2]);
        dxy = abs(ipx(1)-ipy(1));
    end
    
    [t1,x1,y1,x2,y2] = deal(t1,x1,y1,x2,y2);
    t2 = t2 - d;
    
    end
    

    gives the desired plot:

    enter image description here

    0 讨论(0)
提交回复
热议问题