フィルターのクリア

interpolating the 2d line to make the new coordinates equi-distant

15 ビュー (過去 30 日間)
tafteh
tafteh 2013 年 2 月 12 日
Hi all;
I have a 2d line which is a x and y vector. I would like to interpolate that line such that the new x, y coordinates are uniformly distributed along the line. I mean I get a line which the x and y coordinate are equi-distance. As if we are moving along this curve with constant speed.
Is there any way to do this? I would appreciate if you could help me out in this.
Thanks

採用された回答

Sven
Sven 2013 年 2 月 12 日
Hi Payam, try this:
pathXY = [0 0; 1 1; 10 2; 12 3]
stepLengths = sqrt(sum(diff(pathXY,[],1).^2,2))
stepLengths = [0; stepLengths] % add the starting point
cumulativeLen = cumsum(stepLengths)
finalStepLocs = linspace(0,cumulativeLen(end), 100)
finalPathXY = interp1(cumulativeLen, pathXY, finalStepLocs)
Is that what you were looking for?

その他の回答 (1 件)

tafteh
tafteh 2013 年 2 月 14 日
Thanks a ton Sven. That is the answer I needed. Appreciate it.
However, out of my cuorisity, why do we have to calculate the cumulutive sum of all the distances? Can we have the
linspace(0, sum(stepLengths), 100)
instead of
linspace(0,cumulativeLen(end), 100)?
or there any other reason to calculate the cumulativeLen vector?
thanks, Payam
  1 件のコメント
Sven
Sven 2013 年 2 月 14 日
Check out the help for the interp1 function - it takes as its first argument something that relies on the true distance between each of your input points. If you simply use linspace(0,finalDist,100), then you will be telling MATLAB "all my points are equally spaced apart" (even though they are not).
There is no difference between sum(stepLengths) and cumulativeLen(end)... it's just that I already have (and need) the cumLen so I may as well use it rather than make a new sum.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by