Reputation: 1395
What is the best way of finding the shift along the x-axis for the blue line in this image
such that it matches the red line? The result has to look like this image
). In MATLAB there are complex function like fminunc but I have to deal with some time constraints, so I'm wondering if there are more efficient ways.
Edit: The data is coming from range measurements of an laser scan in a simulated environment. On the x-axis you see the bearing of each scan in radians versus the range measured in meters on the y-axis. For the red points (the reference scan) the bearings are indeed evenly spaced out. This is always the case for the reference scan, but not for the current scan (the blue points).
Edit: data for the red points
-1.5708 6.8542
-1.3963 6.9530
-1.2217 7.2137
-1.0472 7.6592
-0.8727 8.3326
-0.6981 9.2984
-0.5236 10.6477
-0.3491 12.5060
-0.1745 15.0092
0 18.2745
0.1745 22.3368
0.3491 27.1113
0.5236 32.4112
0.6981 38.0010
And for the blue points
-1.3963 7.0092
-1.2217 7.3112
-1.0472 7.8065
-0.8727 8.5420
-0.6981 9.5872
-0.5236 11.0407
-0.3491 13.0360
-0.1745 15.7225
0 19.1849
0.1745 23.4301
0.3491 28.3466
0.5236 32.4114
Upvotes: 3
Views: 335
Reputation: 38032
OK, it's not the "best" way, but it's a way if you don't know the proper model that describes the curve:
% your first plot
figure(1), clf, hold on
plot(red(:,1), red(:,2), 'ro-')
plot(blue(:,1), blue(:,2), 'bo-')
% approximate reference with splines, so it can be evaluated anywhere
ppred = spline(red(:,1),red(:,2));
% minimize the distance between the curves
f = @(x) norm( ppval(ppred, blue(:,1)+x)-blue(:,2) );
x0 = fminsearch(f, 0);
blue(:,1) = blue(:,1)+x0;
% pretty close to your second plot
plot(blue(:,1), blue(:,2), 'ko-')
Upvotes: 1